reference
1 min read
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
| Option | Effect |
|---|---|
-a, --all |
Print every setting, in a readable layout. |
-g, --save |
Print 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:
| Setting | Effect |
|---|---|
echo / -echo |
Show / hide typed characters — -echo is how a password prompt hides input. |
rows N / cols N |
Tell the terminal its size. |
| A number | Set the connection speed (baud rate). |
stty has a large catalogue of settings; stty -a shows them all with their current values.
Choosing the terminal
| Option | Effect |
|---|---|
-F, --file=DEVICE |
Operate on DEVICE instead of the terminal on standard input. |
Exit status
stty returns 0 on success, and non-zero if a setting was invalid or the terminal could not be accessed.
See also
Peios Learn
Built with Trail