stty命令

在Linux中,终端是我们不可或缺的工具,因此十分有必要对其的各种属性进行了解。


stty - change and print terminal line settings
stty命令用于修改中断的各种设置或者打印出终端的各种设置。
  1. digdeep@ubuntu:~$ stty
  2. speed 38400 baud; line = 0;
  3. eol = M-^?; eol2 = M-^?; swtch = M-^?;
  4. ixany iutf8
  5. digdeep@ubuntu:~$ stty -a
  6. speed 38400 baud; rows 24; columns 80; line = 0;
  7. intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?;
  8. swtch = M-^?; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
  9. lnext = ^V; flush = ^O; min = 1; time = 0;
  10. -parenb -parodd cs8 hupcl -cstopb cread -clocal -crtscts
  11. -ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
  12. -iuclc ixany imaxbel iutf8
  13. opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
  14. isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
  15. echoctl echoke
  16. digdeep@ubuntu:~$
stty -a命令输出了终端的所有的属性设置。下面我们来详细的解释各个比较重要的属性的含义。
<1> 将中断的输入和输出速度设置为指定 speed (以位/秒为单位)
<2> rows 24; columns 80; 是指终端默认的大小为24行,80列。就是每一行80个字符,总共24行。
<3> intr = ^C; Ctrl+C: send an interrupt signal.发送中断信号,经常用于中断一个命令的执行。
<4> quit = ^\Ctrl+\: send a quit signal. 发送退出信号。经常用于推出一个命令或程序。
<5> erase = ^?Ctrl+?: erase the last character typed. 将我们在终端输入的字符行删除。
<6> kill = ^UCtrl+U: erase the current line. 将终端上的一行字符删除。
注:Ctrl+? 没有 Ctrl+U 强大。前者只能将我们输入的字符删除,比如我们通过按向上的箭头得到的输入,就不能通过Ctrl + ? 来删除掉。而后者 Ctrl + U 没有这样的限制。所以一般使用后者。
另还有几个个经常用的快捷键:
Ctrl+A:作用是将光标置为输入字符的最前面。比如当我们输入一条命令: pon dsl-provider,提示没有权限。此时我们可以:先按向上的方向键,然后Ctrl+A,最后输入sudo回车 当然高手可以:直接输入sudo !! 再回车
Ctrl+L:相当于我们在终端上输入clear指令,用于清屏。
Tab+Tab:在command后面具有命令补全的功能,command的参数后面具有路径补齐的功能。
<7> eof = ^D;   Ctrl+D: send an end of file. 发送一个文件结束符合,常用于终止命令行的输入。
<8> start = ^QCtrl+Q: restart the output after stopping it. 重新打开命令向终端的输出。
<9> stop = ^S;  Ctrl+S: stop the output. 关闭命令向终端的输出。
<10>susp = ^Z;  Ctrl+Z: send a terminal stop signal. 发送将命令挂起的信号。
<11> werase = ^WCtrl+W: erase the last word typed. 将最后输入的一个单词删除。
<12> flush = ^OCtrl+O: 刷新输入的缓存。

上面的都是通过赋值来设置的各种终端的属性。下面的都是通过“打开/关闭”来设置的各种终端的属性。其中前面带有-的表示该属性关闭没有-的表示该属性打开
关于输入:
<13> cs8 : set character size to N bits, N in [5..8]. 字符的大小
<14> cread : allow input to be received. 允许接收输入。
<15> brkint: breaks cause an interrupt signal. 中断时发出 INTR 信号。
<16> icrnl : input convert return to newline. 输入时将 CR回车键 映射为 NL换行符'\n'。
<17> ixon :  enable XON/XOFF flow control.  启用 START/STOP 输出控制。一旦启用 START/STOP 输出控制,您可以按下Ctrl-S 按键顺序暂停向工作站的输出,也可按下 Ctrl-Q 按键顺序恢复输出。
<18>ixany: let any character restart output, not only start character. 允许任何字符重新启动输出。
<19>imaxbel: 即(input max bell) beep and do not flush a full input buffer on a character. 
                         当输入溢出时,回送 BEL 字符并且废弃最后的输入字符。
<20>iutf8:assume input characters are UTF-8 encoded. 输入字符为UTF-8编码 

关于输出:
<21> opost: postprocess output. 处理输出。
<22> onlcr: (output newline convert to return). translate newline to carriage return-newline.输出时             将换行符'\n'转换成回车符号输出.

Local settings:

<23> icanon: enable erase, kill, werase, and rprnt special characters. 经典输入模式,或者说规范输入模式。
<24> echo : echo input characters. 回显输入字符。
<25>isig: enable interrupt, quit, and suspend special characters
<26>iexten: enable non-POSIX special characters

。。。 。。。

还有一个与stty相似的命令:tty
tty - print the file name of the terminal connected to standard input
  1. digdeep@ubuntu:~$ tty
  2. /dev/pts/1
打印我们的伪终端的名字。

你可能感兴趣的:(Shenzhen_ever)