Identify terminal device in Linux

In this article, we cover how to identify a terminal device in Linux. When we open a terminal in graphical Linux environment, it would start a pseudo-terminal. In the background, Linux associates a device file for each terminal session we open.

And, it associates device files for each terminal session we open. These device files are unique to each terminal session.

A pseudo-terminal as the term suggests is not a terminal itself. But, its a special communication channel that acts like one. There are two ends to the channel i.e. master and slave.

Coming back to device files, for every terminal session there is a device file. But, where are these device files stored?

The device files which are created as a result of opening a terminal session are stored in the directory – /dev/pts

Identify terminal device in Linux

How can we identify such device files?

We can identify device files (or, active terminal session) through the following command –

tty

If its the first terminal session that we have opened then, it would return with –

/dev/pts/0

For subsequent terminal sessions, it would be – /dev/pts/1, /dev/pts/2 etc. Here, device files are 0, 1, 2 etc. in the directory /dev/pts

We can verify the devices files in the directory through the following command –

ls -l /dev/pts

What happens when we close a terminal session?

The moment we close a terminal session, its associated device file gets destroyed. Just check it yourself. Close the terminal session with device file – /dev/pts/0. And, then do ls -l /dev/pts. This time around you won’t get info related to /dev/pts/0 device file.

But, when we again open a new terminal session, device file /dev/pts/0 is allocated to it. So, from here we understand that device files can be reused even after they get destroyed.

In conclusion, we have covered here how to identify terminal device in Linux.

Similar Posts