When you interact with a Linux system, you are doing so through a terminal interface. Historically, this meant sitting at a physical teletypewriter (TTY) wired directly to a mainframe. Today, it usually means opening a software terminal emulator on your desktop (a pseudo-terminal, or PTY) or connecting remotely via SSH. Because Linux treats everything as a file—including hardware devices and terminal sessions—your current connection has a specific, absolute file path associated with it in the /dev directory. To find out exactly which “file” represents your current terminal, you use the tty command.
Basic Usage of the tty Command
The tty command stands for “teletypewriter,” paying homage to the mechanical origins of UNIX computing. Running the command is as simple as typing its name and pressing Enter.
tty
If you are using a modern graphical desktop environment like GNOME or KDE and you open a standard terminal window, the output will likely look something like this:
/dev/pts/0
This output tells you that your session is a “pseudo-terminal slave” (pts) assigned the identification number zero. If you open a second tab in your terminal application and run the command again, it will output /dev/pts/1.
Conversely, if you drop out of the graphical interface entirely and switch to a raw, full-screen virtual console (e.g., by pressing Ctrl+Alt+F3), running the command will output something like:
/dev/tty3
This indicates you are connected directly to the system’s core teletype handler.
Silent Mode for Scripting
While printing the file path is useful for human administrators, tty is most frequently used by automated Bash scripts to determine whether they are being run interactively by a human or silently in the background (like via a cron job).
If a script is run by a background process, it is not attached to any terminal, and the tty command will output not a tty. To use this programmatically without printing messy text to the screen, you can use the -s (silent) flag.
tty -s
When used with the silent flag, tty outputs absolutely nothing. Instead, it silently returns an exit status code to the operating system:
- Exit Code 0: The standard input is a terminal (a human is likely watching).
- Exit Code 1: The standard input is not a terminal (the script is running headless).
Bash scripts can evaluate this exit code (using $?) to intelligently decide whether to prompt the user for input or to automatically proceed with default values.