When you are logged into a massive, multi-user Linux mainframe, you might be connected via an SSH tunnel, a serial console port, or a pseudo-terminal emulator running inside a graphical desktop window. In Linux, absolutely everything is treated as a file, and your specific terminal session is no exception. It is physically represented by a device file hidden deep within the /dev/ directory. To discover the exact filename of the terminal you are currently typing into, you must use the tty command.
How to Print Your Terminal Filename
The tty (Teletypewriter) command is incredibly simple and requires zero configuration or administrative privileges.
Open your terminal window and type:
tty
When you press Enter, the system will instantly output an absolute file path. If you are using a modern graphical desktop (like GNOME or KDE) and opened a terminal emulator window, the output will likely look like this:
/dev/pts/0
The pts stands for “pseudo-terminal slave.” The number 0 means you are the very first pseudo-terminal opened since the server booted. If you open a second tab in your terminal window and run the command again, it will output /dev/pts/1.
If you are connected via a direct, hardwired physical keyboard attached to the server rack (a pure TTY console), the output will drop the “pts” designation entirely and look something like /dev/tty1.
How to Send Messages to Other Terminals
Because your terminal is literally just a text file sitting in the /dev/ directory, it obeys standard Linux file manipulation rules. You can use this knowledge to broadcast messages directly onto other users’ screens.
If your coworker is logged into the server via SSH, and they run the tty command and tell you their session is /dev/pts/2, you can use the echo command to inject text directly into their live terminal session.
From your own terminal (assuming you have sufficient permissions), type:
echo "Please log off, rebooting server in 5 minutes" > /dev/pts/2
The moment you press Enter, that warning message will instantly appear on their screen, interrupting whatever they were typing.
Using tty in Bash Scripts
If you are writing a bash script that is designed to run silently in the background (as a cron job or a systemd service), it will not be attached to a human terminal. If a script attempts to run an interactive command (like prompting for a password) while running in the background, it will crash.
You can use the -s (silent) flag in your scripts to safely test for a terminal connection:
tty -s
If the script is attached to a real terminal, the command returns a successful exit code (0). If it is running blindly in the background, it returns a failure code (1), allowing your if/then logic to safely bypass the interactive password prompt.