Glossary

tty

tty stands for "teletype", a reference to the physical teleprinters that were once the standard way of interacting with mainframes. In Linux, a "tty" is any terminal device: a virtual console (/dev/tty1 through /dev/tty6), a pseudo-terminal for a terminal emulator (/dev/pts/0, etc.), or a serial line. The command tty prints the device currently attached to your standard input:

tty
/dev/pts/3

Switching between virtual consoles with Ctrl+Alt+F1 through Ctrl+Alt+F6 takes you through the kernel's text-mode consoles. They exist even on a graphical desktop and are invaluable when X or Wayland breaks—a working tty is often the only way to log in and fix things.

A subtler use of "tty" is to check whether a program's standard input or output is connected to a terminal or to a file/pipe. Scripts often branch on if [[ -t 1 ]]; then ... fi to decide whether to emit colour codes. Programs like ls use this to colourise output only when running interactively, avoiding garbage characters when their output is redirected into a file.

Related terms: Terminal

Discussed in:

Also defined in: Textbook of Linux