Linux is a powerful and versatile operating system that is used in many different types of computing environments. One of the most important aspects of Linux is its ability to manage different types of devices, including terminals. In this article, we will discuss the differences between the three most common terminal devices in Linux: /dev/tty, /dev/tty0, and /dev/console. We will explain the purpose of each device and how they are used in Linux. Finally, we will discuss how to access and configure these devices.
Linux: Difference Between /dev/tty, /dev/tty0, and /dev/console
/dev/tty is a generic device file that refers to the current terminal.
/dev/tty0 is the first virtual console. It is used to access the system console.
/dev/console is the device file that is used to access the system console. It is the default device file for the system console.
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.
Difference Between /dev/tty, /dev/tty0, and /dev/console
In Linux, the
/dev/console are all special files that are used to access the terminal. They are all related to the terminal, but they have different purposes.
/dev/tty file is a special file that is used to access the current terminal session. It is used to access the terminal from within a program or script. It is also used to access the terminal from a remote session.
/dev/tty0 file is a special file that is used to access the first virtual terminal. It is used to access the terminal from the console or from a remote session.
/dev/console file is a special file that is used to access the system console. It is used to access the terminal from the system console or from a remote session.
The main difference between the three files is the purpose they are used for. The
/dev/tty file is used to access the current terminal session, the
/dev/tty0 file is used to access the first virtual terminal, and the
/dev/console file is used to access the system console.