tty (Unix)
In Unix-like operating systems, "tty" is an abbreviation for "teletypewriter," but its usage has broadened significantly beyond its original meaning. It generally refers to a terminal device, which can be a physical terminal connected to the system, a virtual terminal provided by the operating system, or a pseudo-terminal (pty) used for remote access and other applications.
A tty device file in the /dev directory represents a communication endpoint between the system and a user or process. These files act as interfaces through which input and output data are exchanged.
There are several types of ttys:
-
Physical Terminals: These are actual hardware devices, like serial terminals, directly connected to the system. They are increasingly rare.
-
Virtual Consoles: These are terminals that are emulated directly by the kernel, allowing multiple login sessions on a single physical display. They are typically accessed using key combinations like Ctrl+Alt+F1 through Ctrl+Alt+F6.
-
Pseudo-Terminals (ptys): These are virtual terminal devices that are not directly associated with a physical terminal. They are used extensively for network connections (e.g., SSH sessions), terminal emulators running within a graphical environment, and programs that need to simulate a terminal interaction, such as
expect
.
The tty
command can be used to print the filename of the terminal connected to standard input. If standard input is not a terminal, an error message is displayed.