stty 命令说明及使用讲解
来源:互联网 发布:java编程学不会 编辑:程序博客网 时间:2024/05/16 10:56
可以在stty命令中使用-a查看当前注册终端的设置情况。
$ stty -a
Speed 9600 baud; line =0;intr= DEL;quit = ^;erase = ^h;kill =^U;eof = ^d;start=^q;stop=^s
-parenb -parodd cs8 -cstopb -hupcl cread -clocal -loblk
-ignbrk brkint ignpar -parmrk -inpck istrip -inlcr -igncr icrnl-iuclc
ixon ixany -ixoff
isig icanon -xcase echo echoe echok -echonl -noflsh
opost -olcuc onlcr -ocrnl -onocr onlret ofill ofdel tab3
需要时,这里显示的各种选择都可以重新配置。每种终端选项都有自己的名字(如ixon),其中大多数要么被设置要么被清除。在stty中相应选项前冠以负号(-),该选项被清除(禁止);如果无负号,该选项被设置。
当希望修改各选择的值时,应在stty命令中正确书写相应选项。如命令
$ stty -ixon
将流控制设置为OFF,而命令
$ stty ixon
则将其置为ON。在stty命令中可以同时设置多个选项:
$ stty ixon 1200
该命令将终端设置为1200波特,并将流控制置为ON。
当选项的列表较长时,应当小心所做的修改造成会话的混乱。典型的情况下,终端在设置不正确时完全不能工作。经常出现的现象是列输出显示或用户的击键不能被shell正确接受。有时NEWLINE可能只显示或走一行但不回行,即用户输入的NEWLINE符不能被shell正确读取。建立新注册标识的过程通常建立了正确的stty选项,在日常使用中很少需要修改。但如果变量TERM的设置不正确或用户希望使用新的终端或通信渠道(如局域网),则需要修改stty的选项。如果你在某个机器中注册后终端操作正常,但后来因故发生了混乱,那么最佳的解决方法是先注销然后再向系统注册。因为注册时系统会重新设置相应选项。还有一种不太严格的解决办法是:
$ stty sane
命令sane最常出现在大多数终端的stty选项的集合中。它并不改变通信信道的速率,但当终端发生混乱时,通常能够产生有益的效果。命令sane可能使全屏幕应用程序(如vi)不能正确工作,而且在设置了选项sane之后,如果不能解决任何问题,就应立即注销,然后再注册。如果终端在注册后依然不能正确工作,用户的注册可能是不成功的。如果终端已经混乱,NEWLINE键不能结束命令行,可以用CTRL-J代替NEWLINE直到用户执行sttysane。此时,再用CTRL-J终止stty sane,使系统恢复正常。
stty命令的几项主要选项功能为:
选项parenb使终端进行奇偶校验,-parenb则是禁止校验;
选项cs5、cs6、cs7和cs8分别将字符大小设为5、6、7和8比特;
选项300、600、1200、2400、4800、9600和19200设置波特率;
cstopb和-cstopb分别设置两个或一个停止位;
tabs使系统使用制表符而不是空格序列,因此减少了输出量,选项-tabs仅使用空格,当终端不能正确处理制表符(tab)时应使用该项。
2.stty还可用于控制一些具有特殊控制功能的键。系统可能已经使用CTRL-D作为文件结束符,但你可能喜欢使用CTRL-C。因此可以使用stty命令改变之:
$ stty eof c
其中c可以是你喜欢的其它特殊控制字符。
可以直接输入控制字符,在其前面冠以反斜线和脱字符( ^)。命令
$ stty eof ^c
将CTRL-C设置为文件结束符。这种语法形式还可以用于修改删除符(通常为退格键BackSpace)和中断符(通常为DEL键)。若希望将删除符改为BACKSPACE,可以使用下列命令:
$ stty erase ^h
可以设置一个会话期,使得当自己键入一个退格键时,系统用退格、删除和退格序列响应。此时可以看到用退格键覆盖的字符从显示中消失了,这样更符合计算机的惯例。使用命令
$ stty echoe
可使这一特性设置为ON。
总览
stty [-F device] [--file=device] [SETTING]...
stty [-F device] [--file=device] [-a|--all]
stty [-F device] [--file=device] [-g|--save]
quot; Add any additional description here
打印或改变终端属性.
-a, --all
以可读的格式打印当前的所有设置
-g, --save
以终端可读的格式打印当前的所有设置
-F, --file
打开指定的设备,并用此设备作为输入来代替标准输入
--help
显示帮助并退出
--version
显示版本信息并退出
选项-在SETTING之前使用这些选项将被视为无效 星号*表明是非POSIX设置.以下是一些系统定义了的
可用设置:
特殊字符
* dsusp CHAR CHAR表示输入满时,发一个停止信号给终端
eof CHAR
CHAR表示一个文件结束 (结束输入)
eol CHAR
CHAR表示当前行结束
* eol2 CHAR CHAR是另一个表示结束当前行的字符
erase CHAR
CHAR表示擦除最后一个输入字符
intr CHAR
CHAR表示发一个中断信号
kill CHAR
CHAR表示擦除当前行
* lnext CHAR CHAR表示输入下一个字符
quit CHAR
CHAR表示发出一个退出信号
* rprnt CHAR CHAR表示刷新当前行
start CHAR
CHAR表示在停止输出后重新开始输出
stop CHAR
CHAR表示停止输出
susp CHAR
CHAR表示发送一个终端停止信号
* swtch CHAR CHAR表示切换到不同的外壳层
* werase CHAR CHAR表示擦除已经输入的最后一个单词
特殊设置
N
把输入和输出的波特率设为N
* cols N 通知内核终端有N列
* columns N 与cols N 相同
ispeed N
设置输入速度为N
* line N 用行约束规则N
min N
用 -icanon, 设置一次完整的读操作最小为N个字符
ospeed N
设置输出速度为N
* rows N 通知内核终端有N行
* size 根据内核打印出终端的行数和列数
speed
打印出终端的速度
time N
同时用 -icanon, 设置读超时为十分之N秒
控制设置
[-]clocal
关闭解调器的控制信号
[-]cread
允许接收输入
* [-]crtscts 允许 RTS/CTS 的握手
csN
把字符长度设为N, N 为[5..8]
[-]cstopb
对每字符使用两个停止位 (一个带有 `-')
[-]hup
当最后一个进程关闭终端后,发一个挂起信号
[-]hupcl
同 [-]hup
[-]parenb
在输出中产生奇偶校验位,并要求在输入中也有奇偶校验位
[-]parodd
设置奇校验 (偶校验用 `-')
输入设置:
[-]brkint
暂停并产生中断信号
[-]icrnl
将回车解释为换行
[-]ignbrk
忽略中断信号
[-]igncr
忽略回车符
[-]ignpar
忽略有奇偶校验错的字符
* [-]imaxbel 对一个字符产生嘟叫,但不刷新已满的输入缓冲区
[-]inlcr
将换行解释为回车
[-]inpck
打开输入奇偶校验
[-]istrip
清除输入字符的高位(第8位)
* [-]iuclc 将大写字符转换成小写字符
* [-]ixany 使任何字符都重新开始输出(而 不仅仅是重新输出字符能实现此功能)
[-]ixoff
打开发送开始/停止字符的开关
[-]ixon
打开XON/XOFF的流量控制
[-]parmrk
标记奇偶校验错误 (使用255-0-character 字符序列)
[-]tandem
同 [-]ixoff
输出设置:
* bsN 回退延迟, N 为 [0..1]
* crN 回车延迟, N 为 [0..3]
* ffN 换页延迟, N 为 [0..1]
* nlN 换行延迟, N 为 [0..1]
* [-]ocrnl 将回车解释为换行
* [-]ofdel 使用删除字符来填充,而不是用空字符填充
* [-]ofill 使用填充字符,不使用定时延迟
* [-]olcuc 将小写字符转换成大写
* [-]onlcr 将换行解释为回车-换行
* [-]onlret 换行执行一次回车
* [-]onocr 不在第一列打印回车
[-]opost
postprocess 输出
* tabN 水平tab键延迟, N 为 [0..3]
* tabs 同tab0
* -tabs 同tab3
* vtN 垂直方向tab键延迟。。。, N 为 [0..1]
本地设置:
[-]crterase
将擦除字符显示为:退格-空格-退格
* crtkill 根据echoprt和echoe的设置去除所有行
* -crtkill 根据echoctl和echok设置去除所有行
* [-]ctlecho 在头部符号中显示控制字符'^c')
[-]echo
显示输入字符
* [-]echoctl 同 [-]ctlecho
[-]echoe
同[-]crterase
[-]echok
在一个杀死字符后显示一个换行
* [-]echoke 同 [-]crtkill
[-]echonl
即使不显示其它字符也换行
* [-]echoprt 向后显示在 '' 和 '/'之间的擦除字符
[-]icanon
打开 erase, kill, werase, 和 rprnt 这些特殊字符
[-]iexten
打开 非POSIX 特殊字符
[-]isig
打开中断,退出和挂起这些特殊字符
[-]noflsh
在中断和退出这些特殊字符后禁止刷新
* [-]prterase 同 [-]echoprt
* [-]tostop 停止试图写终端的后台作业
* [-]xcase 与icanon同时使用, 表示用`'退出大写状态
综合设置:
* [-]LCASE 同 [-]lcase
cbreak
同 -icanon
-cbreak
同 icanon
cooked
同 brkint ignpar istrip icrnl ixon opost isig icanon, eof 和 eol字符被设为默认值
-cooked
同 raw
crt
同 echoe echoctl echoke
dec
同 echoe echoctl echoke -ixany intr ^c erase 0177 kill ^u
* [-]decctlq 同 [-]ixany
ek
将擦除,杀死字符设为它们的默认值
evenp
同 parenb -parodd cs7
-evenp
同 -parenb cs8
* [-]lcase 同 xcase iuclc olcuc
litout
同 fB-parenb -istrip -opost cs8
-litout
同 parenb istrip opost cs7
nl
同 -icrnl -onlcr
-nl
同 icrnl -inlcr -igncr onlcr -ocrnl -onlret
oddp
同 parenb parodd cs7
-oddp
同 -parenb cs8
[-]parity
同 [-]evenp
pass8
同 -parenb -istrip cs8
-pass8
同 parenb istrip cs7
raw
同 -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr-icrnl -ixon -ixoff -iuc lc -ixany -imaxbel -opost -isig -icanon-xcase min 1 ti me 0
-raw
同 cooked
sane
同 cread -ignbrk brkint -inlcr -igncr icrnl -ixoff -iuclc -ixanyimaxbel opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0cr0 tab0 bs0 vt0 ff 0 isig icanon iexten echo echoe echok -echonl-noflsh -xcase -tostop -echoprt echoctl echoke, 所有特殊字符 使用缺省值.
本命令处理连接到标准输入的终端行.如不带参数,则输出波特率, 行的约束规则,以及与健全 的stty相背离的设置.在设置中,CHAR 是逐字读取的, 或是象 ^c, 0x37, 0177 或127这样的 编码; 特殊值 ^-或未定义被用来禁止特殊字符.
====
http://blog.chinaunix.net/u/19203/showart_1913815.html
-------------------------------------------------------------------------------------------------------------------------
命令参考大全
stty 命令
用途
设置、复位和报告工作站操作参数。
语法
stty [ -a ] [ -g ][ Options ]
描述
stty 命令对当前为标准输入的设备设置某些 I/O 选项。该命令将输出写到当前为标准输出的设备中。
这个操作系统的版本使用标准 《X/Open 可移植性指南,发行版 4》 接口来控制终端,保持与 POSIX 和 BSD 接口的兼容性。stty 命令支持 POSIX 和 BSD 的适应选项,但强烈推荐使用 POSIX 选项。同样提供废弃的 BSD 选项列表(带有对应的 POSIX 选项)。
输入以下命令时,可以将 tty 设备的标准输入重定向:
stty -a </dev/ttyx
stty 命令(POSIX)将挂起并等待该 tty 的 open(),直到确定 RS-232 载波检测信号。如果设置了 clocal 或 forcedcd(仅对 128 端口)选项,这个规则将不适用。
标志
-a将所有选项设置的当前状态写到标准输出中。-g将选项设置写到标准输出中,其格式可以由另一个 stty 命令使用。选项
stty 命令支持以下选项类别:
- 控制模式
- 输入方式
- 输出方式
- 本地模式
- 硬件流量控制模式
- 控制字符指定
- 组合模式
- 窗口大小
硬件流量控制模式
这些选项是对 《X/Open 可移植性指南,发行版 4》 标准的扩展。
cdxon输出时启用 CD 硬件流量控制模式。-cdxon输出时禁用 CD 硬件流量控制模式。ctsxon输出时启用 CTS 硬件流量控制模式。-ctsxon输出时禁用 CTS 硬件流量控制模式。dtrxoff输入时启用 DTR 硬件流量控制模式。-dtrxoff输入时禁用 DTR 硬件流量控制模式。rtsxoff输入时启用 RTS 硬件流量控制模式。-rtsxoff输入时禁用 RTS 硬件流量控制模式。控制指定
要将一个控制字符指定到某字符串中,请输入:
stty Control String
其中,Control 参数可以是 INTR、QUIT、ERASE、KILL、EOF、EOL、EOL2、START、STOP、SUSP、DSUSP、
REPRINT、DISCARD、WERASE、LNEXT、MIN 或 TIME 参数。(使用字符 MIN 和 TIME 时,请加上 -icanon 选项。)
String 参数可以是任何单一的字符,比如 c。以下内容为控制赋值的示例:
stty STOP c
另一种指定控制字符的方法可以是:输入一个字符序列,它是由一个 \^ (反斜杠,插入记号) 后面跟着一个单一字符组成的。如果跟在 ^ (插入记号)后的单一字符是下表的^c(插入记号 c)栏中列出的字符之一,将设置相应的控制字符值。例如,要使用 ?(问号)字符指定 DEL 控制字符,请输入字符串\^?(反斜杠,插入记号,问号),如下:
stty ERASE \^?
废弃选项
stty 命令支持以下 BSD 选项。 对于每个选项,都给出了建议的 POSIX 选项。
all使用 stty -a 命令显示所有当前设置。crt使用 sane 选项将参数重新设置为合理的值。crtbs使用 -echoe 选项。crterase使用 echoe 选项。-crterase使用 -echoe 选项。crtkill使用 echoke 选项。-crtkill使用 echok 和 -echoke 选项。ctlecho使用 echoctl 选项。-ctlecho使用 -echoctl 选项。decctlq使用 -ixany 选项。-decctlq使用 ixany 选项。even使用 evenp 选项。-even使用 -evenp 选项。everything使用 stty -a 命令显示所有当前设置。litout使用 -opost 选项。-litout使用 opost 选项。odd使用 oddp 选项。-odd使用 -oddp 选项。pass8使用 -istrip 选项。-pass8使用 istrip 选项。prterase使用 echoprt 选项。speed使用 stty 命令显示当前设置。tandem使用 ixoff 选项。-tandem使用 -ixoff 选项。示例
- 要显示您的工作站配置的简短列表,请输入:
stty
这将列出与缺省值不同的设置。
- 要显示您的工作站配置的完整列表,请输入:stty -a
- 要启用停止列表滚动出屏幕的按键顺序,请输入:
stty ixon ixany
这将设置 ixon 模式,从而可以通过按下 Ctrl-S 按键顺序来停止列表的滚动。ixany 标志允许按任意键来恢复列表的滚动。正常的工作站配置包含ixon 和ixany 标志,使您可以用 Ctrl-S 按键顺序停止列表的滚动,而只有 Ctrl-Q 按键顺序才能使列表重新滚动。
- 要重新设置搞乱的配置,请输入:Ctrl-J stty sane Ctrl-J在命令前后按 Ctrl-J 按键顺序,而不是按 Enter 键。当控制 Enter 键处理的参数搞乱时,系统通常能识别 Ctrl-J 按键顺序。
有时屏幕上显示的信息可能看上去很奇怪,或当您按 Enter 键时系统不反应。当您使用 stty 命令,而它带有不兼容的参数或参数的操作难以理解时,可能会发生这种情况。当面向屏幕的应用程序异常结束并且无法复位工作站配置时,也可能发生这种情况。
输入 stty sane 命令设置合理的配置,但它可能与您的正常配置略有不同。
- 要保存和恢复终端的配置:
OLDCONFIG=`stty -g` # save configurationstty -echo # do not display passwordecho "Enter password: \c"read PASSWD # get the passwordstty $OLDCONFIG # restore configuration
该命令保存工作站的配置、关闭回送信号、读取密码并恢复原始配置。
输入 stty - echo 命令关闭回送信号,这意味着当您在键盘上输入密码时,密码并不出现在屏幕上。此操作与echo 命令(该命令在屏幕上显示消息)毫无关系
====
http://study.chyangwa.com/IT/AIX/aixcmds5/stty.htm#amcmi3a1manu
----------------------------------------------------------------------------------------------------
4.5.2. The stty Command
The name stty probably means "set tty," but the stty command can also be used to display a terminal's configuration. Perhaps even more so thansetserial, thestty command provides a bewildering number of characteristics you can configure. We'll cover the most important of these in a moment. You can find the rest described in thestty manual page.
The stty command is most commonly used to configure terminal parameters, such as whether characters will be echoed or what key should generate a break signal. We explained earlier that serial devices are tty devices and thestty command is therefore equally applicable to them.
One of the more important uses of the stty for serial devices is to enable hardware handshaking on the device. We talked briefly about hardware handshaking earlier. The default configuration for serial devices is for hardware handshaking to be disabled. This setting allows "three wire" serial cables to work; they don't support the necessary signals for hardware handshaking, and if it were enabled by default, they'd be unable to transmit any characters to change it.
Surprisingly, some serial communications programs don't enable hardware handshaking, so if your modem supports hardware handshaking, you should configure the modem to use it (check your modem manual for what command to use), and also configure your serial device to use it. The stty command has a crtscts flag that enables hardware handshaking on a device; you'll need to use this. The command is probably best issued from therc.serial file (or equivalent) at boot time using commands like those shown inExample 4-3.
Example 4-3. Example rc.serial stty Commands
# stty crtscts < /dev/ttyS0 stty crtscts < /dev/ttyS1 stty crtscts < /dev/ttyS2 stty crtscts < /dev/ttyS3 #
The stty command works on the current terminal by default, but by using the input redirection ("<") feature of the shell, we can havestty manipulate any tty device. It's a common mistake to forget whether you are supposed to use "<" or ">"; modern versions of thestty command have a much cleaner syntax for doing this. To use the new syntax, we'd rewrite our sample configuration to look like that shown inExample 4-4.
Example 4-4. Example rc.serial stty Commands Using Modern Syntax
# stty crtscts -F /dev/ttyS0 stty crtscts -F /dev/ttyS1 stty crtscts -F /dev/ttyS2 stty crtscts -F /dev/ttyS3 #
We mentioned that the stty command can be used to display the terminal configuration parameters of a tty device. To display all of the active settings on a tty device, use:
$ stty -a -F /dev/ttyS1
The output of this command, shown in Example 4-5, gives you the status of all flags for that device; a flag shown with a preceding minus, as in–crtscts, means that the flag has been turned off.
Example 4-5. Output of stty -a Command
speed 19200 baud; rows 0; columns 0; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; -parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -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
A description of the most important of these flags is
given in Table 4-2. Each of these flags is enabled by supplying it tostty and disabled by supplying it tostty with the – character in front of it. Thus, to disable hardware handshaking on thettyS0 device, you would use:
$ stty -crtscts -F /dev/ttyS0
Table 4-2. stty Flags Most Relevant to Configuring Serial Devices
Flags Description
N
Set the line speed to N bits per second.
crtsdts
Enable/Disable hardware handshaking.
ixon
Enable/Disable XON/XOFF flow control.
clocal
Enable/Disable modem control signals such as DTR/DTS and DCD. This is necessary if you are using a "three wire" serial cable because it does not supply these signals.
cs5 cs6 cs7 cs8
Set number of data bits to 5, 6, 7, or 8, respectively.
parodd
Enable odd parity. Disabling this flag enables even parity.
parenb
Enable parity checking. When this flag is negated, no parity is used.
cstopb
Enable use of two stop bits per character. When this flag is negated, one stop bit per character is used.
echo
Enable/Disable echoing of received characters back to sender.
The next example combines some of these flags and sets the ttyS0 device to 19,200 bps, 8 data bits, no parity, and hardware handshaking with echo disabled:
$ stty 19200 cs8 -parenb crtscts -echo -F /dev/ttyS0
====
http://linux.about.com/od/lna_guide/a/gdelna38t01.htm
- stty 命令说明及使用讲解
- stty 命令说明及使用讲解
- stty 命令说明及使用讲解
- stty命令说明及使用详解
- stty命令说明及使用详解
- stty命令使用
- stty命令使用
- stty命令使用一例
- stty 命令
- stty命令
- stty 命令
- stty命令
- stty命令
- stty命令
- stty 命令
- stty命令
- stty 命令
- stty命令
- eclipse中字体设置
- C# 字符串转化为时间格式
- LINUX内核编译方法以及其步骤(在READ HAT LINUX 5.0上面运行成功)
- 堆排序算法及实现
- 三种素数筛选法详解
- stty 命令说明及使用讲解
- 通过asp.net 短信猫发短信
- 巴什博弈
- 为什么要在addsubview:一个view对象后,release它
- HDU-2046 骨牌铺方格【递推】
- const关键字的深入理解
- win7系统,配置oracle的net manager保存出错的解决办法
- phpMyAdmin3 remote code execute php版本 exploit
- PJBlog 3.2.9.518 getwebshell 漏洞