stty, STTY -- set terminal modes


stty [ -a | -g ] [ -- ]

stty [ -cdn ] [ -F/dev/devicename | -f /dev/devicename ] mode ... [ -- ]


The stty command sets certain terminal I/O modes; without arguments, it reports the current settings.

The -a option reports all mode settings.

The -g option outputs the current stty settings as a list of fourteen hexadecimal numbers separated by colons. (This output can be used as a command line argument to stty to restore these settings at a later time. It is more compact than stty -a). The format of the output depends on the line discipline selected (using the line mode).

The -c, -d, and -n options determine how changes are carried out. If -d (``drain'') is given, changes occur after all pending output has been transmitted. If -c (``clear input'') is used, changes also occur after all pending output has been transmitted, and further, before the changes are made any pending input is discarded. If -n (``now'') is specified, changes occur immediately. (These correspond to the TCSADRAIN, TCSAFLUSH, and TCSANOW values for the optional-actions parameter to tcsetattr(); see termios(S) for more information.) If no changes are specified on the stty command line, -c, -d, and -n have no effect. (The -d behavior is the default; it is provided so that other flags used in an stty alias can be overridden. The last instance of a flag in a command line takes precedence.)

The -f and -F options specify a device name (as opposed to using the standard input). Only one instance of -f or -F can be used. These options are provided for compatibility with other versions of stty and differ in syntax. If -F is used, the device name can be given separately or in the same parameter: -F/dev/devicename. For -f, the device name is supplied in a separate argument: -f /dev/devicename. (This is neccessary to differentiate this option from stty modes that begin with ``f.'') Both options open the device in non-blocking mode, allowing stty to operate on devices that cannot be opened using the shell redirection operator.

stty understands the end-of-options delimiter (--).

STTY is a link to stty.

Terminal modes

The various modes are discussed in the following sections: Detailed information about the modes listed in the sections ``Common control modes'' to ``Window size modes'' may be found on the termio(M) and termios(M) manual pages.

The modes in the section ``Combination modes'' are implemented using multiple modes from the other sections.

Refer to vidi(C) for hardware specific information that describes control modes for the video monitor and other display devices.

Common control modes

Hang up phone line immediately.

ispeed speed
ospeed rate
Set the serial line speed in bits per second (bps) to one of 50, 75, 110, 134, 134.5, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 19.2, 38400 or 38.4, 57600, 76800, 115200, 230400, 460800, or 921600. ispeed and ospeed set the input and output serial line speed respectively.

clocal (-clocal)
Assume a line without (with) modem control.

cread (-cread)
Enable (disable) the receiver.

cs5 cs6 cs7 cs8
Select character size (see termio(M)).

cstopb (-cstopb)
Use two (one) stop bits per character.

ctsflow (-ctsflow)
Enable (disable) CTS handshaking for a modem or non-modem line.

hup (-hup)
Same as hupcl (-hupcl).

hupcl (-hupcl)
Hang up (do not hang up) phone connection on last close.

ortsfl (-ortsfl)
Enable unidirectional (enable bidirectional) flow control if ctsflow and rtsflow are both set. The following table shows the flow control modes available by combining the ortsfl, ctsflow, and rtsflow flags:

Flag settings Flow control mode
ortsfl rtsflow ctsflow Enable unidirectional flow control
ortsfl rtsflow -ctsflow Assert RTS when ready to send
ortsfl -rtsflow ctsflow No effect
ortsfl -rtsflow -ctsflow Enable bidirectional flow control
-ortsfl rtsflow ctsflow Enable bidirectional flow control
-ortsfl rtsflow -ctsflow No effect
-ortsfl -rtsflow ctsflow Stop transmission when CTS drops
-ortsfl -rtsflow -ctsflow Disable hardware flow control

 Flag settings               Flow control mode
 ortsfl rtsflow ctsflow      Enable unidirectional
                             flow control
 ortsfl rtsflow -ctsflow     Assert RTS when ready
                             to send
 ortsfl -rtsflow ctsflow     No effect
 ortsfl -rtsflow -ctsflow    Enable bidirectional
                             flow control
 -ortsfl rtsflow ctsflow     Enable bidirectional
                             flow control
 -ortsfl rtsflow -ctsflow    No effect
 -ortsfl -rtsflow ctsflow    Stop transmission when
                             CTS drops
 -ortsfl -rtsflow -ctsflow   Disable hardware flow

parenb (-parenb)
Enable (disable) parity generation and detection.

parext (-parext)
Set extended parity for mark and space parity (SVID3 line discipline only).

parodd (-parodd)
Select odd (even) parity.

rtsflow (-rtsflow)
Enable (disable) RTS handshaking for a modem or non-modem line.

Input modes

brkint (-brkint)
Signal (do not signal) INTERRUPT on break.

cs2scancode (-cs2scancode)
Put console keyboard into codeset 2/(AT) mode (or codeset 1/(XT) mode) and interpret the transmitted codes accordingly.

icrnl (-icrnl)
Map (do not map) CR to NL on input.

ignbrk (-ignbrk)
Ignore (do not ignore) break on input.

igncr (-igncr)
Ignore (do not ignore) CR on input.

ignpar (-ignpar)
Ignore (do not ignore) parity errors.

imaxbel (-maxbel)
Echo ASCII BEL if the input line is too long. Further input is discarded. If not set, BEL is not echoed and the contents of the input queue are discarded (SVID3 line discipline only).

inlcr (-inlcr)
Map (do not map) NL to CR on input.

inpck (-inpck)
Enable (disable) input parity checking.

isscancode (-isscancode)
Expect the terminal device to send (not send) PC scancodes.

istrip (-istrip)
Strip (do not strip) input characters to 7 bits.

iuclc (-iuclc)
Map (do not map) uppercase alphabetics to lowercase on input.

ixany (-ixany)
Allow any character (only DC1) to restart output.

ixoff (-ixoff)
Request that the system send (not send) START/STOP characters when the input queue is nearly empty/full.

ixon (-ixon)
Enable (disable) START/STOP output control. Output is stopped by sending an ASCII DC3 and started by sending an ASCII DC1.

parmrk (-parmrk)
Mark (do not mark) parity errors (see termio(M)).

xscancode (-xscancode)
Translate (do not translate) PC scancodes to characters on input.

Output modes

bs0 bs1
Select style of delay for BACKSPACEs (see termio(M)).

cr0 cr1 cr2 cr3
Select style of delay for RETURNs (see termio(M)).

ff0 ff1
Select style of delay for FORMFEEDs (see termio(M)).

nl0 nl1
Select style of delay for LINEFEEDs (see termio(M)).

ocrnl (-ocrnl)
Map (do not map) CR to NL on output.

ofdel (-ofdel)
Fill characters are DELETEs (NULs).

ofill (-ofill)
Use fill characters (uses timing) for delays.

olcuc (-olcuc)
Map (do not map) lowercase alphabetics to uppercase on output.

onlcr (-onlcr)
Map (do not map) NL to CR NL on output.

onlret (-onlret)
On the terminal NL perform (do not perform) the CR function.

onocr (-onocr)
Do not (do) output CRs at column zero.

opost (-opost)
Post-process output (do not post-process output; ignore all other output modes).

tab0 tab1 tab2 tab3

Select style of delay for horizontal TABs (see termio(M)). -tabs is equivalent to tab3: expand tabs into spaces.

vt0 vt1
Select style of delay for vertical TABs (see termio(M)).

Expand tabs into spaces; equivalent to tab3 (SVID3 line discipline only).

Local modes

autoe (-autoe)
Show whether autoerase is set (L_SETERASE flag). Supported only for SCO OpenServer Release 5.0.6 and later.

echo (-echo)
Echo back (do not echo back) every character typed.

echoctl (-echoctl)
Echo a control character as ^C, where C is the character obtained by adding 100 octal to the control character's ASCII code. delete is echoed as ^? (SVID3 line discipline only).

echoe (-echoe)
Echo (do not echo) ERASE character as a BS SP BS (BACKSPACE, SPACE, BACKSPACE) sequence. Note: this mode will erase the ERASE character on many CRT terminals; however, it does not keep track of column position and, as a result, may be confusing on escaped characters, TABs, and BACKSPACEs.

echok (-echok)
Echo (do not echo) NL after KILL character.

echoke (-echoke)
Erase every character in a line using the method selected by echoe and echoprt. By default, this is the sequence BS SP BS (SVID3 line discipline only).

echonl (-echonl)
Echo (do not echo) NL.

echoprt (-echoprt)
If echo and echoprt are defined, echo the first ERASE and WERASE characters in a sequence as backslash (\) followed by the characters being erased. Following ERASE and WERASE characters echo the erased characters in reverse order. The next character that is not ERASE or WERASE outputs a slash (/) before it itself is echoed (SVID3 line discipline only).

flusho (-flusho)
Discard data written to the terminal. -flusho can be used to cancel the effect of a FLUSH character being typed (SVID3 line discipline only).

icanon (-icanon)
Enable (disable) canonical input (ERASE and KILL processing).

iexten (-iexten)
Enable extended implementation functions for the SVID3 line discipline. By default, -iexten is set; the control characters discard, lnext, reprint, and werase are not processed, and the settings of echoctl, echoke, echoprt, flusho, pendin, and tostop are ignored.

isig (-isig)
Enable (disable) the checking of characters against the special control characters INTERRUPT, SWITCH and QUIT.

lfkc (-lfkc)
The same as echok (-echok); this mode is obsolescent.

noflsh (-noflsh)
Disable (enable) flush after INTERRUPT or QUIT.

pendin (-pendin)
Reprint any input that has not yet been read when the next input character arrives (SVID3 line discipline only).

tostop (-tostop)
Disable (enable) background process group to write to controlling terminal (only if the shell supports job control).

xcase (-xcase)
Canonical (unprocessed) upper/lowercase presentation. Echo (do not echo) NL after KILL character.

Control assignments

control-character C
Set control-character to C, where control-character is one of: erase, kill, intr (interrupt), quit, eof, eol, swtch (switch), start, stop, or susp.

If the svid line discipline is being used (SVID3), the following control-characters are also available: dsusp, flush, lnext, rprnt, and werase.

If C is preceded by a caret (^) (escaped from the shell), then the value used is the corresponding control character (for example, ^D is a <Ctrl>d, ^? is interpreted as DELETE). The setting ^- disables the control character.

See termio(M) and termios(M) for a definition of the control characters.

line i
Set the line discipline to i in the range 0 LESS THAN OR EQUAL TO i LESS THAN OR EQUAL TO 127.

line 0
line tty
Set the line discipline to tty. See termio(M).

line 6
line svid
Set the line discipline to svid (SVID3). See termios(M).

line \?
Print the available line disciplines.

min i
time i
When -icanon is set, and one character has been received, read requests are not satisfied until at least min characters have been received or the timeout value time (in units of 100ms) has expired and one character has been received. The valid range for i is 0 LESS THAN OR EQUAL TO i LESS THAN OR EQUAL TO 127. See termio(M).

Window size modes

These modes redefine the display size:

cols n
columns n
Set the screen width as a number, n, of columns of characters.

rows n
Set the screen height as a number, n, of rows of lines.

xpixels n
Set the screen width to n picture elements (pixels).

ypixels n
Set the screen height to n picture elements (pixels).

Combination modes

Reset ERASE and KILL characters back to normal <Ctrl>h and <Ctrl>u.

evenp or parity
Enable parenb and cs7.

lcase (-lcase)
Set (unset) xcase, iuclc, and olcuc.

nl (-nl)
Unset (set) icrnl, onlcr. In addition -nl unsets inlcr, igncr, ocrnl, and onlret.

Enable parenb, cs7, and parodd.

-parity, -evenp, or -oddp
Disable parenb, and sets cs8.

Enable raw input and output (no ERASE, KILL, INTERRUPT, QUIT, EOT, or output post-processing). raw is equivalent to the settings:

cs8 -parenb -isig -icanon -xcase -opost -inpck min 1 time 1


Disable raw input and output. Using -raw or cooked is equivalent to setting:

cs7 parenb brkint ignpar istrip icrnl ixon isig icanon opost \
eof ^D eol ^@

Reset all modes to some reasonable values. Useful when a terminal's settings have been hopelessly scrambled. sane is equivalent to:

cread -clocal brkint ignpar icrnl ixon -ignbrk -parmrk \
-inpck -inlcr -icncr -iuclc -ixoff \
isig icanon echo echok -xcase -echoe -echonl -noflsh -iexten \
opost onlcr -olcuc -ocrnl -onocr -onlret -ofill -ofdel \
bs0 cr0 ff0 nl0 tab0 vt0

xscancode is also set if isscancode is set.

tabs (-tabs or tab3)
Preserve (expand to spaces) tabs when printing.

Set all modes suitable for the terminal type term; one of tty33, tty37, vt05, tn300, ti700, or tek.

saved settings
Set the current terminal characteristics to the saved settings produced by the -g option.


The following shell script uses stty -g to store the current settings, turns off character echo, disables the INTERRUPT control character, and reads a line of input. The stored values are then restored to the terminal:
   echo "Enter your secret code: \c"
   old=`stty -g`
   stty -echo intr '^-'
   read code
   stty $old


The driver for the SVID3 line discipline is not linked into the kernel by default. To link this driver into the kernel:

  1. Edit /etc/conf/sdevice.d/ttsv.

  2. Change the ``N'' entry to ``Y'' and save the file.

  3. Relink the kernel using link_unix(ADM).

  4. Shutdown and reboot your system.
Do not use the -iscancode or -xscancode modes on the console, as the console keyboard always sends scancodes and needs them translated.

The stty -a command displays these mode settings (along with the settings of all other modes). However, if the tty is in -isscancode mode, stty -a does not display the state of xscancode cs2scancode.

Some console keyboards do not support the codeset 2/(AT) mode cs2scancode. Use kbmode(ADM) to determine whether your keyboard supports this mode.

Many combinations of modes make no sense, but no checking is performed.

Note that a window or an application may not have been programmed to recognize a change in the effective screen size. The following flags are defined in SCO OpenServer Release 5.0.6

Future directions

The following flags are defined in the SCO OpenServer Release 5.0.6 stty(C) command and in the termio.h header file but the kernel capability is not included so they are not functional.

ed_emacs (-ed_emacs)
Show (set) emacs command line editing.

ed_history (-ed_history)
Show (set) thatthe terminal supports a history stack. Requires that the ed_emacs or ed_vi flag also be set.

ed_vi (-ed_vi)
Show (set) vi command line editing.

See also

console(HW), kbmode(ADM), ioctl(S), scancode(HW), scanon(M), serial(HW), termio(M), termios(M), tty(M), vidi(C)

Standards conformance

stty is conformant with:

ISO/IEC DIS 9945-2:1992, Information technology - Portable Operating System Interface (POSIX) - Part 2: Shell and Utilities (IEEE Std 1003.2-1992);
AT&T SVID Issue 2;
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992.

© 2004 The SCO Group, Inc. All rights reserved.