TTY basics

TTY is the abbreviation for TeleTYpewriter. A typewriter can be described as a device, which gets input and delivers output. We call such a device a terminal. The methods shown here will partially not work in a terminal emulator, like xterm. That is, because an emulator does not necessarily implement each existing terminal function. I recommend to switch to a real terminal for testing. That can ordinarily be done with [STRG]+[ALT]+{[F1]-[F12]}

Name of the TTY #

A terminal is usually represented by a virtual device under /dev/. Its name is shown by simply calling tty, e.g.:

$ tty

Start and stop TTY's #

Because terminals have such virtual devices and /dev/ is writeable only by the root user, only root can create and destroy terminals and execute these commands successfully:

openvt -c 12 -- ls -la
deallocvt 12
openvt -c 12 -- mingetty tty12
deallocvt 12

line 1 lists the content of the current directory and destroys the terminal again. The -- is there to separate the command from the other parameters.

line 3 starts a login-shell on tty12

Properties of TTY #

A virtual terminal has properties, which are similar to real hardware (think of a two-lined LCD display for example, which may be able to display 2x16 chars). These properties can be displayed by issuing the stty command, like so:

$ stty -a"
speed 38400 baud; rows 20; columns 160; line = 0;
intr = ^C; quit = ^; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <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

line 1 information about the number of lines which fir in one screen and how fast individual chars can be written to it.

lines 2-4 The ^-symbol stands for [CTRL] key. With it stty wants to tell us, that instead of [BACKSPACE] we could also write [CTRL]+[?] (e.g. [CTRL]+[SHIFT]+[=] on an American keyboard).

lines 5-10 For these one should better read man stty. I will make only a few examples here.

Manipulation of properties #

The stty tool can also be used to modify the terminals behavior:

stty -F $(tty) iuclc
stty -iuclc
stty intr ^-
stty rows 20

line 1 enables the translation, which turns all uppercase letters into lowercase

line 2 disables the translation again, the -F is fortunately optional.

line 3 deactivates [CTRL]+[C]

line 4 limits the display to show only 20 lines