search

What does linux stty mean?

Apr 06, 2023 pm 04:23 PM
linux

In Linux, the full name of stty is "set tty", which means "set tty". It is a command used to display and modify terminal (terminal) related settings; the syntax is "stty [option] [setting]" , the stty command without parameters can print the terminal line settings, and adding the "-a" option can print more detailed information.

What does linux stty mean?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

The difference between device file processing and disk files

Let’s talk about a few more intuitive feelings first. First, when you use the keyboard (usually a standard input terminal device), enter characters until you enter the Enter key (Enter on the keyboard is the Enter key, not the line feed key; the ACCII for line feed is 10, and the Enter key is 13; The reflection of line breaks in the program is \n), and your program will "react", giving people the impression that your program only accepts the data you input after pressing Enter;

Secondly , you write a printf("This is a demo\n"); in the program, you will find that your next output starts from the leftmost side of the next line, but the functions of carriage return and line feed are:

 \r is return, carriage return, even if the cursor returns to the head of the current line;

 \n is newline, line break, that is, the cursor moves to The next line from the current position.

 So, it means that the process converted your \n into \r\n. The reason why these occur under Linux is because there is a terminal driver in the middle between the terminal device and the process, which contains terminal driver functions. Here are two pictures for easy understanding.

What does linux stty mean?

What does linux stty mean?

The terminal device driver is responsible for data transmission and data processing between the process and the terminal, and the terminal driver is the kernel part. You can change the settings in the terminal driver through the tesetattr and tegetattr functions

The above is excerpted from this article: https://blog.csdn.net/suliangkuanjiayou/article/details/86665901

Linux stty command

1. Function

In order to be able to write a terminal driver function that suits you, go to Modify the settings in the terminal driver. There is this command in Linux, which is stty (set tty, set tty).

stty: used to display and modify terminal command line related settings (change and print terminal line settings).

2. Syntax

stty [选项] [设置]
stty [选项]

Common options

stty command does not take parameters Terminal line settings can be printed, and the -a parameter can be used to print more detailed information.

stty size: can display the size of the terminal, that is, the number of rows and columns.

The stty command can also change the settings of the terminal line. The format is as follows: stty SETTING CHAR

Among them, SETTING can be as follows:

eof: end of input, file End, default is Ctrl D. For example: when using cat >file to create a file, press Ctrl D to end the input.

erase: Delete characters backward, erase the last input character, the default is Ctrl?. Note that the Backspace key does not delete characters by default.

intr: Interrupt the current program, the default is Ctrl C.

kill: Delete the entire command, delete the entire line, the default is Ctrl U.

quit: Exit the current program, the default is Ctrl \ or Ctrl |.

start: Start screen output, the default is Ctrl Q.

stop: Stop screen output, the default is Ctrl S.

susp: terminal stops the current program, the default is Ctrl Z. In this way, the current process will become a background process.

werase: Delete the last word, the default is Ctrl W.

The stty command has some other uses, such as: stty -echo turns off echo (for example, when used to enter a password in a script), and then uses stty echo to turn on echo.

#在命令行下,禁止输出大写的方法:
stty iuclc     #开启
stty -iuclc    #恢复

#在命令行下禁止输出小写:
stty olcuc    #开启
stty -olcuc   #恢复

#打印出终端的行数和列数:
stty size

#改变Ctrl+D的方法:
stty eof "string"
#系统默认是Ctrl+D来表示文件的结束,而通过这种方法,可以改变!

#屏蔽显示:
stty -echo   #禁止回显
stty echo    #打开回显
#测试方法:
stty -echo;read;stty echo;read

#忽略回车符:
stty igncr     #开启
stty -igncr    #恢复

3、使用示例

下面以xilinx的串口终端为例说明stty命令的使用方法。

在vivad0配置了两个串口分别是UART0和UART1,petalinx中设置UART1为调试串口,UART0和UART1分别对应分别对应/dev/ttyPS1和/dev/ttyPS0,可以用who命令看一下当前终端使用的是哪个串口:

可以看到当前终端使用的是ttyPS0

用 dmesg | grep ttyPS*可以查看当前终端对应哪个串口

可以看到ttyPS0对应串口的物理地址是0xff010000,从设备树中根据这个物理地址可以查到是哪个串口

1)查看当前终端信息:

stty -a

这个打印了当前终端的信息,一些参数解释如下:

speed 115200 baud:波特率是115200

cs8:数据是8位

ixon:流控打开,如果是-ixon则表示流控关闭

clocal:使能DTR/DTS

-parodd:失能奇校验

-parenb:失能奇偶校验

2)设置波特率115200,数据位8位:

  stty -F /dev/ttyPS1 115200 cs8

3)通过UART1发送数据:

  echo "qwert" > /dev/ttyPS1

4)查看UART1接受的数据

cat /dev/ttyPS1

通过串口工具向UART1发送数据,即可看到接受到的信息

  

相关推荐:《Linux视频教程

The above is the detailed content of What does linux stty mean?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Linux Operations: Understanding the Core FunctionalityLinux Operations: Understanding the Core FunctionalityMay 03, 2025 am 12:09 AM

Linux is a Unix-based multi-user, multi-tasking operating system that emphasizes simplicity, modularity and openness. Its core functions include: file system: organized in a tree structure, supports multiple file systems such as ext4, XFS, Btrfs, and use df-T to view file system types. Process management: View the process through the ps command, manage the process using PID, involving priority settings and signal processing. Network configuration: Flexible setting of IP addresses and managing network services, and use sudoipaddradd to configure IP. These features are applied in real-life operations through basic commands and advanced script automation, improving efficiency and reducing errors.

Linux: Entering and Exiting Maintenance ModeLinux: Entering and Exiting Maintenance ModeMay 02, 2025 am 12:01 AM

The methods to enter Linux maintenance mode include: 1. Edit the GRUB configuration file, add "single" or "1" parameters and update the GRUB configuration; 2. Edit the startup parameters in the GRUB menu, add "single" or "1". Exit maintenance mode only requires restarting the system. With these steps, you can quickly enter maintenance mode when needed and exit safely, ensuring system stability and security.

Understanding Linux: The Core Components DefinedUnderstanding Linux: The Core Components DefinedMay 01, 2025 am 12:19 AM

The core components of Linux include kernel, shell, file system, process management and memory management. 1) Kernel management system resources, 2) shell provides user interaction interface, 3) file system supports multiple formats, 4) Process management is implemented through system calls such as fork, and 5) memory management uses virtual memory technology.

The Building Blocks of Linux: Key Components ExplainedThe Building Blocks of Linux: Key Components ExplainedApr 30, 2025 am 12:26 AM

The core components of the Linux system include the kernel, file system, and user space. 1. The kernel manages hardware resources and provides basic services. 2. The file system is responsible for data storage and organization. 3. Run user programs and services in the user space.

Using Maintenance Mode: Troubleshooting and Repairing LinuxUsing Maintenance Mode: Troubleshooting and Repairing LinuxApr 29, 2025 am 12:28 AM

Maintenance mode is a special operating level entered in Linux systems through single-user mode or rescue mode, and is used for system maintenance and repair. 1. Enter maintenance mode and use the command "sudosystemctlisolaterscue.target". 2. In maintenance mode, you can check and repair the file system and use the command "fsck/dev/sda1". 3. Advanced usage includes resetting the root user password, mounting the file system in read and write mode and editing the password file.

Linux Maintenance Mode: Understanding the PurposeLinux Maintenance Mode: Understanding the PurposeApr 28, 2025 am 12:01 AM

Maintenance mode is used for system maintenance and repair, allowing administrators to work in a simplified environment. 1. System Repair: Repair corrupt file system and boot loader. 2. Password reset: reset the root user password. 3. Package management: Install, update or delete software packages. By modifying the GRUB configuration or entering maintenance mode with specific keys, you can safely exit after performing maintenance tasks.

Linux Operations: Networking and Network ConfigurationLinux Operations: Networking and Network ConfigurationApr 27, 2025 am 12:09 AM

Linux network configuration can be completed through the following steps: 1. Configure the network interface, use the ip command to temporarily set or edit the configuration file persistence settings. 2. Set up a static IP, suitable for devices that require a fixed IP. 3. Manage the firewall and use the iptables or firewalld tools to control network traffic.

Maintenance Mode in Linux: A System Administrator's GuideMaintenance Mode in Linux: A System Administrator's GuideApr 26, 2025 am 12:20 AM

Maintenance mode plays a key role in Linux system management, helping to repair, upgrade and configuration changes. 1. Enter maintenance mode. You can select it through the GRUB menu or use the command "sudosystemctlisolaterscue.target". 2. In maintenance mode, you can perform file system repair and system update operations. 3. Advanced usage includes tasks such as resetting the root password. 4. Common errors such as not being able to enter maintenance mode or mount the file system, can be fixed by checking the GRUB configuration and using the fsck command.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor