In this article, we’re talking about the tty command in Linux. The Linux operating system uses file system to represent everything. Not just the text files and images but even the hardware and the terminal. Yes, even the terminal you use to interact with Linux is actually a file.
tty is the command that displays information related to this terminal file.
tty is short for teletype. Historically the word ‘teletype’ comes from the word ‘teletypewriter’. A teletypewriter is an electromechanical device that sends and receives typed messages through various communication channels. That’s very similar to what a terminal does. In fact, in the early days, the first computer terminal was referred to as teletype terminal.
How to use the tty command?
tty prints the name of the terminal file to standard output. To print the name just type ‘tty’ and hit enter.
$tty
Output:
/dev/pts/0
Options with tty command
To know more about tty command you can use the –help as shown below:
$ tty --help
Output :
Usage: tty [OPTION]...
Print the file name of the terminal connected to standard input.
-s, --silent, --quiet print nothing, only return an exit status
--help display this help and exit
--version output version information and exit
We can see that there are only two options available with tty command.
–silent option
When using the silent option along with tty command, no output is seen on the screen. It just returns the exit status.
tty -s
tty --silent
tty --quiet
We can print the exit status out to the screen by using the command :
$ echo $?
Output :
0
What do different exit codes mean?
- 0 : standard input is a terminal
- 1 : standard input is not a terminal
Identify tty version
Using –version option along with tty command gives the version of tty you are using.
$ tty --version
Output :
tty (GNU coreutils) 8.30
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by David MacKenzie.
Conclusion
In this tutorial, we covered tty command. To learn more about the tty command refer to its man page. Although this tutorial covers everything there is to learn about the command.