TrumanWong

tty

Displays the file name of the terminal device connected to the current standard input.

Summary

tty [option] ...

The main purpose

  • Display the file name of the terminal device connected to the current standard input, printing "not a tty" when the standard input is not a terminal.

Options

-s, --silent, --quiet Do not print any information, only return the exit status.
--help Display help information and exit.
--version Display version information and exit.

return value

When using -s, --silent, --quiet, a return code of 0 indicates that standard input is a terminal, a return code of 1 indicates that standard input is not a terminal, a return code of 2 indicates an option error, and a return code of 3 indicates that there is A write error occurred.

example

Displays the file name of the terminal device connected to the current standard input.

[root@localhost ~]# tty
/dev/pts/2

Find the process associated with the terminal (assuming it is pts/2)

# Note that the TTY column is filtered.
ps -ef | egrep "pts/2 " | grep -v grep

Notice

  1. This command is a command in the GNU coreutils package. For related help information, please see man -s 1 tty, info coreutils 'tty invocation'.