tty
system administrationLinux/Unix
The tty command is one of the most frequently used commands in Linux/Unix-like operating systems. tty Print the file name of the terminal connected to standard input
Quick Reference
Command Name:
tty
Category:
system administration
Platform:
Linux/Unix
Basic Usage:
tty [options] [arguments]
Common Use Cases
Syntax
tty [OPTION]...
Options
Option | Description |
---|---|
-s, --silent, --quiet |
Print nothing, only return an exit status |
--help |
Display help and exit |
--version |
Output version information and exit |
Examples
How to Use These Examples
The examples below show common ways to use the tty
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
Print the terminal device name
tty
Check the exit status without printing the terminal name
tty -s && echo "Standard input is a terminal"
Advanced Examples:
Use in a script to determine if input is from a terminal
if tty -s; then
Find out which pseudo-terminal a process is connected to
ps -o tty,command -p $$
Check if a specific terminal is active
who | grep $(tty | cut -d/ -f3-)
Use with other commands in a pipeline
tty | xargs ls -l