Linux / UNIX supports device files that are stored in the /dev directory. These aren’t actual files, rather, they are special files or character devices that are representative of hardware devices attached to the system.
Some of the most commonly misunderstood device files are /dev/console, /dev/tty, and /dev/tty0. In this guide, we will explore the nuances that distinguish these three device files.
What is /dev/tty in Linux
“tty” is short for TeleTYpewriter. It has its origin in the early terminals that were used to connect to computers as teleprinters or teletypewriters.
The /dev/tty file is a special file that represents the terminal for the current process, which displays the terminal associated with the current SSH session.
To check which tty you are currently using, run the following command:
$ tty OR $ who am i
The output shows that the current tty is /dev/pts/0. This stands for Pseudo Terminal Slave and is a terminal device emulated by SSH connections or other programs such as xterm or screen.
What is /dev/tty[0-N] in Linux
/dev/tty[0-N] is simply a virtual console that you can switch to from the main terminal if you are running a GUI system where
N represents the TTY number. By default, /dev/tty0 is the default virtual console.
For example, if you are running a graphical instance of Ubuntu 22.04, launch your terminal and type
CTRL + ALT + F1, which will open a black terminal screen as shown below.
As you can see, from the output, we are using tty1 where
1 corresponds to the Function Key pressed.
tty1 through tty63 are virtual terminals, alternatively known as VTs or virtual consoles. And as mentioned, they simulate multiple consoles on top of the physical console device driver.
What is /dev/console in Linux
/dev/console is referred to as the system console, where the boot and kernel messages are displayed on this console during booting. Like other Linux device files, it resides in the /dev directory.
You can confirm by running the following ls command as follows.
$ ls -lah /dev/console
/dev/console exists primarily to expose the kernel’s console to user space. It shows messages during system startup (and shutdown as well) and also facilitates the switchover to single-user mode using the init 1 command.
It’s our hope that you can now pick the differences that exist across the three device files that we have just covered. Your feedback on this guide is welcome.
1 thought on “Linux: Difference Between /dev/tty, /dev/tty0, and /dev/console”
Thanks for explaining about the difference between /dev/tty, /dev/tty0, and /dev/console in Linux, which is very helpful for beginners and freshers.