Home > Article > Operation and Maintenance > What does linux stty mean?
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.
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
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.
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
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!