22867

114 分钟

#Bash 的 stty 命令

stty [OPTION]... [SETTING]...

功能

查看或修改终端配置。

类型

可执行文件(/usr/bin/stty),属于 coreutils

参数

  • OPTION 选项:
    • -a, --all - 以易于阅读的形式打印所有当前终端设置
    • -g, --save - 以紧凑格式打印所有当前终端设置
    • -F, --file=DEVICE - 指定终端设备
    • --help - 显示帮助
    • --version - 显示版本
  • SETTING - 设置项列表

#设置项说明

特殊字符说明备注
discard CHARCHAR 将切换(开启/关闭)输出丢弃功能非 POSIX 标准
eof CHARCHAR 将发送文件结束符(终止输入)-
eol CHARCHAR 将结束当前行-
eol2 CHAR用于结束行的备用 CHAR非 POSIX 标准
erase CHARCHAR 将删除最后输入的一个字符-
intr CHARCHAR 将发送中断信号-
kill CHARCHAR 将删除当前整行-
lnext CHARCHAR 将以字面值方式输入下一字符(引用输入)非 POSIX 标准
quit CHARCHAR 将发送退出(quit)信号-
rprnt CHARCHAR 将重新绘制当前行非 POSIX 标准
start CHARCHAR 将在停止后恢复输出-
stop CHARCHAR 将停止输出-
susp CHARCHAR 将发送终端挂起(stop)信号-
swtch CHARCHAR 将切换到另一个 shell 层非 POSIX 标准
werase CHARCHAR 将删除上一个单词非 POSIX 标准
特殊设置说明备注
N将输入和输出速度设置为 N 波特率-
cols N告诉内核终端宽度为 N 列非 POSIX 标准
columns N等同于 cols N非 POSIX 标准
[-]drain在应用新设置前等待传输完成(默认启用)非 POSIX 标准
ispeed N将输入速度设置为 N-
line N使用编号为 N 的 line discipline(行规程)非 POSIX 标准
min N在使用 -icanon 时,设置读取完成所需的最少字符数-
ospeed N将输出速度设置为 N-
rows N告诉内核终端高度为 N 行非 POSIX 标准
size打印内核记录的终端行数与列数非 POSIX 标准
speed打印终端当前速度-
time N在使用 -icanon 时,设置读取超时时间(N × 0.1 秒)-
控制设置说明备注
[-]clocal禁用或启用调制解调器控制信号(- 为禁用,默认依系统而定)-
[-]cread允许或禁止接收输入-
[-]crtscts启用或关闭 RTS/CTS 硬件握手流控非 POSIX 标准
csN设置字符位宽为 N 位(N 取值范围 5~8)-
[-]cstopb每个字符使用两个停止位(加 - 时为使用一个停止位)-
[-]hup当最后一个进程关闭 TTY 时发送挂断信号-
[-]hupcl等同于 [-]hup-
[-]parenb输出中生成奇偶校验位,并在输入时要求奇偶校验位-
[-]parodd使用奇校验(加 - 时使用偶校验)-
[-]cmspar使用 "stick" 校验方式(mark/space parity)非 POSIX 标准
输入设置说明备注
[-]brkintbreak 字符会触发中断信号-
[-]icrnl将回车符(CR)转换为换行符(NL)-
[-]ignbrk忽略 break 字符-
[-]igncr忽略回车符(CR)-
[-]ignpar忽略带奇偶校验错误的字符-
[-]imaxbel当输入缓冲区满时发出响铃(不清空缓冲区)非 POSIX 标准
[-]inlcr将换行符(NL)转换为回车符(CR)-
[-]inpck启用输入奇偶校验检查-
[-]istrip清除输入字符的第 8 位(只保留低 7 位)-
[-]iutf8假定输入字符是 UTF-8 编码非 POSIX 标准
[-]iuclc将大写字符转换为小写非 POSIX 标准
[-]ixany输入任意字符都可重新启动输出(不只限 start 字符)非 POSIX 标准
[-]ixoff启用发送 XOFF/XON 的控制字符(软件流控)-
[-]ixon启用接收 XON/XOFF 流控-
[-]parmrk用 255-0-字符 的序列标记奇偶校验错误-
[-]tandem等同于 [-]ixoff-
输出设置说明备注
bsN退格(Backspace)延时样式,N 取值范围 0~1非 POSIX 标准
crN回车(Carriage Return)延时样式,N 取值范围 0~3非 POSIX 标准
ffN换页(Form Feed)延时样式,N 取值范围 0~1非 POSIX 标准
nlN换行(Newline)延时样式,N 取值范围 0~1非 POSIX 标准
[-]ocrnl将回车符(CR)转换为换行符(NL)非 POSIX 标准
[-]ofdel填充字符使用 DEL(0x7F),而不是 NUL(0x00)非 POSIX 标准
[-]ofill使用填充字符(padding)而不是基于时间的延迟非 POSIX 标准
[-]olcuc将小写字母转换为大写字母非 POSIX 标准
[-]onlcr将换行符(NL)转换成回车-换行(CR-NL)非 POSIX 标准
[-]onlret换行符(NL)同时执行回车(CR)动作非 POSIX 标准
[-]onocr在当前列为第一列时不输出回车符(CR)非 POSIX 标准
[-]opost启用或禁用输出后处理-
tabN水平制表符(tab)延时样式,N 取值范围 0~3非 POSIX 标准
tabs等同于 tab0非 POSIX 标准
-tabs等同于 tab3非 POSIX 标准
vtN垂直制表符(vertical tab)延时样式,N 取值范围 0~1非 POSIX 标准
本地设置说明备注
[-]crterase将删除字符以“退格-空格-退格”的方式回显-
crtkill按照 echoprtechoe 的设置删除(kill)整行非 POSIX 标准
-crtkill按照 echoctlechok 的设置删除(kill)整行非 POSIX 标准
[-]ctlecho以帽号表示法(如 ^C)回显控制字符非 POSIX 标准
[-]echo回显输入字符-
[-]echoctl等同于 [-]ctlecho非 POSIX 标准
[-]echoe等同于 [-]crterase-
[-]echok在 kill 字符后回显一个换行符-
[-]echoke等同于 [-]crtkill非 POSIX 标准
[-]echonl即使不回显其他字符,也回显换行符-
[-]echoprt以反向方式回显被删除的字符,并包围在 \/ 之间非 POSIX 标准
[-]extproc启用 LINEMODE(适用于高延迟链接)非 POSIX 标准
[-]flusho丢弃正在输出的数据非 POSIX 标准
[-]icanon启用特殊字符:erase,kill,werase,rprnt-
[-]iexten启用非 POSIX 的扩展特殊字符-
[-]isig启用中断,退出与挂起(suspend)特殊字符-
[-]noflsh禁止在中断或退出字符后刷新缓冲区-
[-]prterase等同于 [-]echoprt非 POSIX 标准
[-]tostop阻止后台任务向终端写入(会发送 SIGTTOU)非 POSIX 标准
[-]xcase在 canonical 模式下,对大写字母加 \ 进行转义非 POSIX 标准
组合设置说明备注
[-]LCASE等同于 [-]lcase非 POSIX 标准
cbreak等同于 -icanon(关闭规范模式,单字符输入)-
-cbreak等同于 icanon(开启规范模式)-
cooked将 brkint ignpar istrip icrnl ixon opost isig icanon eof 和 eol 字符恢复默认值-
-cooked等同于 raw(关闭规范模式并应用 raw 设置)-
crt等同于 echoe echoctl echoke-
dec等同于 echoe echoctl echoke -ixany intr ^C erase 0177 kill ^U-
[-]decctlq等同于 [-]ixany非 POSIX 标准
ek将 erase 和 kill 字符恢复默认值-
evenp等同于 parenb -parodd cs7(偶校验,7 位字符)-
-evenp等同于 -parenb cs8(关闭奇偶校验,8 位字符)-
[-]lcase等同于 xcase iuclc olcuc(小写字母处理相关)非 POSIX 标准
litout等同于 -parenb -istrip -opost cs8-
-litout等同于 parenb istrip opost cs7-
nl等同于 -icrnl -onlcr-
-nl等同于 icrnl -inlcr -igncr onlcr -ocrnl -onlret-
oddp等同于 parenb parodd cs7(奇校验,7 位字符)-
-oddp等同于 -parenb cs8(关闭奇偶校验,8 位字符)-
[-]parity等同于 [-]evenp-
pass8等同于 -parenb -istrip cs8(8 位字符,无奇偶校验)-
-pass8等同于 parenb istrip cs7-
raw等同于关闭多种选项:-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -icanon -opost -isig -iuclc -ixany -imaxbel -xcase min 1 time 0-
-raw等同于 cooked-
sane等同于开启 cread -ignbrk brkint -inlcr -igncr icrnl icanon iexten echo echoe echok -echonl -noflsh -ixoff -iutf8 -iuclc -ixany imaxbel -xcase -olcuc -ocrnl opost -ofill onlcr -onocr -onlret nl0 cr0 tab0 bs0 vt0 ff0 isig -tostop -ofdel -echoprt echoctl echoke -extproc -flusho,以及所有特殊字符恢复默认值-

#示例

$ stty -a # 易于阅读的终端设置 speed 38400 baud; rows 55; columns 230; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0; -parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc

#推荐阅读

#手册

STTY(1) User Commands STTY(1) NAME stty - change and print terminal line settings SYNOPSIS stty [-F DEVICE | --file=DEVICE] [SETTING]... stty [-F DEVICE | --file=DEVICE] [-a|--all] stty [-F DEVICE | --file=DEVICE] [-g|--save] DESCRIPTION Print or change terminal characteristics. Mandatory arguments to long options are mandatory for short options too. -a, --all print all current settings in human-readable form -g, --save print all current settings in a stty-readable form -F, --file=DEVICE open and use the specified DEVICE instead of stdin --help display this help and exit --version output version information and exit Optional - before SETTING indicates negation. An * marks non-POSIX settings. The underlying system defines which settings are available. Special characters: * discard CHAR CHAR will toggle discarding of output eof CHAR CHAR will send an end of file (terminate the input) eol CHAR CHAR will end the line * eol2 CHAR alternate CHAR for ending the line erase CHAR CHAR will erase the last character typed intr CHAR CHAR will send an interrupt signal kill CHAR CHAR will erase the current line * lnext CHAR CHAR will enter the next character quoted quit CHAR CHAR will send a quit signal * rprnt CHAR CHAR will redraw the current line start CHAR CHAR will restart the output after stopping it stop CHAR CHAR will stop the output susp CHAR CHAR will send a terminal stop signal * swtch CHAR CHAR will switch to a different shell layer * werase CHAR CHAR will erase the last word typed Special settings: N set the input and output speeds to N bauds * cols N tell the kernel that the terminal has N columns * columns N same as cols N * [-]drain wait for transmission before applying settings (on by default) ispeed N set the input speed to N * line N use line discipline N min N with -icanon, set N characters minimum for a completed read ospeed N set the output speed to N * rows N tell the kernel that the terminal has N rows * size print the number of rows and columns according to the kernel speed print the terminal speed time N with -icanon, set read timeout of N tenths of a second Control settings: [-]clocal disable modem control signals [-]cread allow input to be received * [-]crtscts enable RTS/CTS handshaking csN set character size to N bits, N in [5..8] [-]cstopb use two stop bits per character (one with '-') [-]hup send a hangup signal when the last process closes the tty [-]hupcl same as [-]hup [-]parenb generate parity bit in output and expect parity bit in input [-]parodd set odd parity (or even parity with '-') * [-]cmspar use "stick" (mark/space) parity Input settings: [-]brkint breaks cause an interrupt signal [-]icrnl translate carriage return to newline [-]ignbrk ignore break characters [-]igncr ignore carriage return [-]ignpar ignore characters with parity errors * [-]imaxbel beep and do not flush a full input buffer on a character [-]inlcr translate newline to carriage return [-]inpck enable input parity checking [-]istrip clear high (8th) bit of input characters * [-]iutf8 assume input characters are UTF-8 encoded * [-]iuclc translate uppercase characters to lowercase * [-]ixany let any character restart output, not only start character [-]ixoff enable sending of start/stop characters [-]ixon enable XON/XOFF flow control [-]parmrk mark parity errors (with a 255-0-character sequence) [-]tandem same as [-]ixoff Output settings: * bsN backspace delay style, N in [0..1] * crN carriage return delay style, N in [0..3] * ffN form feed delay style, N in [0..1] * nlN newline delay style, N in [0..1] * [-]ocrnl translate carriage return to newline * [-]ofdel use delete characters for fill instead of NUL characters * [-]ofill use fill (padding) characters instead of timing for delays * [-]olcuc translate lowercase characters to uppercase * [-]onlcr translate newline to carriage return-newline * [-]onlret newline performs a carriage return * [-]onocr do not print carriage returns in the first column [-]opost postprocess output * tabN horizontal tab delay style, N in [0..3] * tabs same as tab0 * -tabs same as tab3 * vtN vertical tab delay style, N in [0..1] Local settings: [-]crterase echo erase characters as backspace-space-backspace * crtkill kill all line by obeying the echoprt and echoe settings * -crtkill kill all line by obeying the echoctl and echok settings * [-]ctlecho echo control characters in hat notation ('^c') [-]echo echo input characters * [-]echoctl same as [-]ctlecho [-]echoe same as [-]crterase [-]echok echo a newline after a kill character * [-]echoke same as [-]crtkill [-]echonl echo newline even if not echoing other characters * [-]echoprt echo erased characters backward, between '\' and '/' * [-]extproc enable "LINEMODE"; useful with high latency links * [-]flusho discard output [-]icanon enable special characters: erase, kill, werase, rprnt [-]iexten enable non-POSIX special characters [-]isig enable interrupt, quit, and suspend special characters [-]noflsh disable flushing after interrupt and quit special characters * [-]prterase same as [-]echoprt * [-]tostop stop background jobs that try to write to the terminal * [-]xcase with icanon, escape with '\' for uppercase characters Combination settings: * [-]LCASE same as [-]lcase cbreak same as -icanon -cbreak same as icanon cooked same as brkint ignpar istrip icrnl ixon opost isig icanon, eof and eol characters to their default values -cooked same as raw crt same as echoe echoctl echoke dec same as echoe echoctl echoke -ixany intr ^c erase 0177 kill ^u * [-]decctlq same as [-]ixany ek erase and kill characters to their default values evenp same as parenb -parodd cs7 -evenp same as -parenb cs8 * [-]lcase same as xcase iuclc olcuc litout same as -parenb -istrip -opost cs8 -litout same as parenb istrip opost cs7 nl same as -icrnl -onlcr -nl same as icrnl -inlcr -igncr onlcr -ocrnl -onlret oddp same as parenb parodd cs7 -oddp same as -parenb cs8 [-]parity same as [-]evenp pass8 same as -parenb -istrip cs8 -pass8 same as parenb istrip cs7 raw same as -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -icanon -opost -isig -iuclc -ixany -imaxbel -xcase min 1 time 0 -raw same as cooked sane same as cread -ignbrk brkint -inlcr -igncr icrnl icanon iexten echo echoe echok -echonl -noflsh -ixoff -iutf8 -iuclc -ixany imaxbel -xcase -olcuc -ocrnl opost -ofill onlcr -onocr -onlret nl0 cr0 tab0 bs0 vt0 ff0 isig -tostop -ofdel -echoprt echoctl echoke -extproc -flusho, all special characters to their default values Handle the tty line connected to standard input. Without arguments, prints baud rate, line discipline, and deviations from stty sane. In settings, CHAR is taken literally, or coded as in ^c, 0x37, 0177 or 127; special values ^- or undef used to disable special characters. AUTHOR Written by David MacKenzie. REPORTING BUGS GNU coreutils online help: <https://www.gnu.org/software/coreutils/> Report any translation bugs to <https://translationproject.org/team/> COPYRIGHT Copyright © 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO Full documentation <https://www.gnu.org/software/coreutils/stty> or available locally via: info '(coreutils) stty invocation' GNU coreutils 9.4 April 2024 STTY(1)

创建于 2025/12/5

更新于 2025/12/5