tty
TLDR
Print the terminal device name
SYNOPSIS
tty [options]
DESCRIPTION
tty prints the file name of the terminal connected to standard input. The output is typically a device path like /dev/pts/0 (pseudo-terminal) or /dev/tty1 (virtual console).
If standard input is not connected to a terminal (e.g., when input is piped or redirected from a file), tty prints "not a tty" and exits with status 1.
The -s option suppresses output entirely, making it useful in scripts where only the exit status matters. This allows testing whether a script is running interactively or in a batch/piped context.
PARAMETERS
-s, --silent, --quiet
Print nothing; only return exit status--help
Display help and exit--version
Output version information and exit
EXAMPLES
Check if running interactively
echo "Running in terminal"
else
echo "Running non-interactively"
fi
echo "Connected to: $MYTERM"
EXIT STATUS
0
Standard input is a terminal1
Standard input is not a terminal2
Invalid option specified
CAVEATS
The tty command only checks standard input. If stdin is redirected but stdout/stderr are still connected to a terminal, tty will report "not a tty". For more detailed terminal checks, consider using test -t or examining /proc/self/fd/.
HISTORY
The tty command dates back to the earliest versions of Unix at Bell Labs in the 1970s. The name comes from "teletypewriter," the original terminal devices. The GNU coreutils version was written by David MacKenzie. The command is specified in POSIX.


