LinuxCommandLibrary

stty

Set or print terminal I/O characteristics

TLDR

Display current terminal size

$ stty size
copy

Display all settings for the current terminal
$ stty [[-a|--all]]
copy

Set the number of rows or columns
$ stty [rows|cols] [count]
copy

Get the actual transfer speed of a device
$ stty [[-F|--file]] [path/to/device_file] speed
copy

Reset all modes to reasonable values for the current terminal
$ stty sane
copy

Switch between raw and normal mode
$ stty [raw|cooked]
copy

Turn character echoing off or on
$ stty [-echo|echo]
copy

Display help
$ stty --help
copy

SYNOPSIS

stty [-a|-g] [-F DEVICE] [SETTING ...]

PARAMETERS

-a
    Print all current settings in human-readable form.

-g
    Print all current settings in stty-readable form (can be used as input to another stty command).

-F DEVICE
    Open and use the specified DEVICE instead of standard input.

SETTING
    Modify a specific terminal setting. Numerous settings exist, including baud rate, control characters (e.g., intr for interrupt character), echoing options, and flow control settings. Refer to the stty man page for a comprehensive list.

raw
    Set raw mode. Input is passed directly without interpretation.

cooked
    Set cooked mode. Enable line editing and other standard terminal features.

echo
    Enable echoing of input characters.

-echo
    Disable echoing of input characters.

ispeed BAUD
    Set the input baud rate to BAUD.

ospeed BAUD
    Set the output baud rate to BAUD.

DESCRIPTION

The stty command is a fundamental utility for controlling the behavior of a terminal interface in Unix-like operating systems. It allows users to configure a wide array of settings related to input, output, and control characters. stty can be used to both display the current terminal settings and to modify them. Its versatility is invaluable for customizing the terminal environment to suit specific needs or to resolve issues related to terminal behavior. Common uses include setting the baud rate, configuring character echoing, and adjusting flow control mechanisms. The command's numerous options provide granular control over nearly every aspect of the terminal, enabling fine-tuning for optimal interaction with command-line applications and other programs. It is critical for programs that relies on consistent terminal behavior.

CAVEATS

Changes made with stty are typically only effective for the current terminal session. To make permanent changes, the command must be included in a shell startup script (e.g., .bashrc or .zshrc). Some settings may be overridden by applications that directly manipulate the terminal.

CONTROL CHARACTERS

stty can be used to set control characters like interrupt (intr), end-of-file (eof), and quit (quit). For example, stty intr ^C sets the interrupt character to Ctrl+C.

FLOW CONTROL

stty can manage flow control mechanisms like XON/XOFF (software flow control) and hardware flow control (using RTS/CTS signals). Options like ixon and ixoff enable and disable XON/XOFF, respectively. crtscts enables hardware flow control.

HISTORY

stty has been a core part of Unix since its early days. Its fundamental role in configuring terminal behavior has ensured its continued presence in virtually all Unix-like operating systems. Over time, the specific options and features of stty have evolved to accommodate new terminal technologies and user needs, but its basic function remains the same: to provide a flexible and powerful means of controlling the terminal environment.

SEE ALSO

tput(1), reset(1)

Copied to clipboard