Linux or UNIX – Find tty name

Posted on in Categories , , last updated December 24, 2006

To print the file name of the terminal connected to standard input (keyboard) you need to use command called tty.

This command is available on Solaris, Linux, FreeBSD, and other Unixish operating systems.

The tty utility writes the name of the terminal attached to standard input to standard output.

You can also use who or w command to find out terminal/tty. Type tty command as follows:
$ tty

Output:
/dev/pts/2

Use following command:
$ tty

Output:

/dev/tty3

You can also use w or who commands to find out tty:
$ w

Output:

NAME     LINE         TIME         COMMENT
vivek    tty1         Feb  6 00:26
root     tty2         Feb  5 14:57

OR use who command:$ who

vivek    tty1         Feb  6 00:26
root     tty2         Feb  5 14:57

In above output second column indicates the tty name.

See also:

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

8 comment

Leave a Comment