The Linux Programming Interface

(nextflipdebug5) #1

1294 Chapter 62


62.3 The stty Command


The stty command is the command-line analog of the tcgetattr() and tcsetattr() functions,
allowing us to view and change terminal attributes from the shell. This is useful
when trying to monitor, debug, or undo the effects of programs that modify termi-
nal attributes.
We can view the current settings of all terminal attributes using the following
command (here carried out on a virtual console):

$ stty -a
speed 38400 baud; rows 25; columns 80; 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 -iutf8
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

The first line of the above output shows the terminal line speed (bits per second),
the terminal window size, and the line discipline in numeric form (0 corresponds
to N_TTY, the new line discipline).
The next three lines show the settings of the various terminal special characters.
The notation ^C denotes Control-C, and so on. The string <undef> means that the corre-
sponding terminal special character is not currently defined. The min and time values
relate to noncanonical mode input, and are described in Section 62.6.2.
The remaining lines show the settings of the various flags from (in order) the
c_cflag, c_iflag, c_oflag, and c_lflag fields of the termios structure. Where a flag name
is preceded by a hyphen (-), the flag is currently disabled; otherwise, it is currently
enabled.
When entered without command-line arguments, stty shows just the terminal
line speed, the line discipline, and any of the other settings that deviate from sane
values.
We can change the settings of terminal special characters using commands
such as the following:

$ stty intr ^L Make the interrupt character Control-L

When specifying a control character as the final argument, we can do so in a variety
of ways:

z as a 2-character sequence consisting of a caret (^) followed by the correspond-
ing character (as shown above);
z as an octal or hexadecimal number (thus: 014 or 0xC); or
z by typing the actual character itself.
Free download pdf