stty

stty displays and changes the settings of a terminal — how it handles input, output, and special keys.

stty [options] [setting...]
$ stty
speed 38400 baud; line = 0;
-brkint -imaxbel iutf8

Run with no arguments, stty prints the settings that differ from the usual defaults. Given setting arguments, it changes them.

Viewing the settings #

OptionEffect
-a, --allPrint every setting, in a readable layout.
-g, --savePrint every setting in a single compact line — a form that can be fed straight back to stty to restore them.

The -g form is how you save and restore a terminal's state:

$ saved=$(stty -g)      # capture the current state
$ stty -echo            # ...change something...
$ stty "$saved"         # restore exactly what was saved

Changing the settings #

A setting argument turns something on or off, or assigns a value. A few common ones:

SettingEffect
echo / -echoShow / hide typed characters — -echo is how a password prompt hides input.
rows N / cols NTell the terminal its size.
A numberSet the connection speed (baud rate).

stty has a large catalog of settings; stty -a shows them all with their current values.

Choosing the terminal #

OptionEffect
-F, --file=DEVICEOperate on DEVICE instead of the terminal on standard input.

Exit status #

CodeMeaning
0The settings were printed or changed.
1A setting was invalid, or the terminal could not be accessed.

Edit this page