Last Updated:

What is TTY on Linux?

The tty command (short for "teletypewriter") displays the name of the terminal you are using in Linux. But what is the backstory behind the name of this team and how can it be useful to us? Let's find out now.

 

Teleprinters from the 1800s

In the 1830s and 1840s, machines known as teleprinters were developed. The teleprinter allowed the sender, using a special device resembling a keyboard, to type messages and send them "by wire" to distant places. According to the reception, the received text was printed out on paper. This was an evolutionary step in telegraphy, which until now used only Morse code and similar codes.

Before sending, the message was encoded, then transmitted to the recipient, at the place of receipt it was decoded and printed. Several methods were used to encode and decode messages. The most famous and popular was the method patented in 1874 by Emile Bodo, after whom the unit of measurement of the symbolic data rate (baud) was named. By the way, his character encoding scheme was 89 years ahead of the advent of the ASCII standard.

The Bodo encoding eventually became the closest to the standard for encoding teleprinters, and therefore, it was adopted by most manufacturers. The original design of Bodo's equipment consisted of only five keys, similar to the keys of a piano. The operator had to learn a certain combination for each letter. Over time, the Bodo encoding system was merged with the traditional keyboard layout.

To commemorate this progress, the machines were called "teletypewriters" or simply "teletypes"In the future, the name was shortened to TTY. That's where the acronym TTY came from. But what does the telegraph have to do with computing?

 

ASCII and Telex


1963 was marked by the release of the ASCII standard, which was adopted by teletype manufacturers. Despite the invention and widespread use of the telephone, the popularity of teletypes was still high.

Telex (short for "telegraph exchange") was a worldwide network of teletypes that allowed written messages to be sent around the world. They were the primary means of transmitting written communications in the post-World War II period until the facsimile (fax) boom in the 1980s.


Soviet fax machine "FTA-P", 1960

At the same time, computers also developed. They became able to interact with users in real time and maintain work with several of them at once. At the same time, the old batch method of working with obsolete devices has increasingly exposed its shortcomings. People did not want to spend a whole day (or even more) waiting for the results of the programs they introduced. Making stacks of punched cards and waiting for the results all night was no longer acceptable: a device was required that would allow you to enter instructions and immediately get the result. We needed efficiency. And teletype has become an ideal candidate for use as an I/O device.

Hardware-emulated teletypes

Teletypes became the standard means of interacting with mini-computers and large mainframes of the era.

Over time, teletypes were replaced by electronic devices that imitated the electromechanical structure of teletypes. But at the same time, these devices used cathode ray tubes (CRTs) instead of rolls of paper, they did not shake when delivering answers from a computer and allowed hitherto impossible functions, such as: moving the cursor around the screen, clearing the screen, highlighting text in bold type, and so on.

The DEC VT05 video terminal was an early example of a virtual teletype and the ancestor of the famous DEC VT100. Sales of the DEC VT100 were in the millions.

 

Software-emulated teletypes


On Linux and other UNIX-like operating systems (such as macOS), the terminal window and applications like x-term and Konsole are examples of virtual teletypes whose operation is fully emulated using software. Because of this feature, the terminals were called pseudo-teletype (abbreviated as pseudo-teletype). "PTS", from the English "pseudo-t eletypes").

tty command

Linux has a pseudo-teletype multiplexer that handles connections from all pseudo-teletype terminals (PTS). The multiplexer is the master device and the PTS is the slave. The multiplexer communicates with the kernel through a device file located in /dev/ptmx.

The tty command displays the name of the special device file that your slave pseudo-teletype uses to communicate with the master device. And that's essentially the number of your terminal window.

Let's see what information the command for our terminal window will output:tty

tty

 

As you can see, we are connected to a special device file /dev/pts/1.

Our terminal window, which is a teletype software emulation (TTY), is connected to the pseudo-teletype multiplexer as pseudo-teletype (PTS) at number 1.

Silent Mode

The option (silent) causes the command to stop generating output:-stty

tty -s

 

Some of the overhead values returned by the tty command are:

   0 - If the standard input comes from a TTY device (emulated or physical).

   1 - If the standard input does not come from the TTY device.

   2 is a syntax error that incorrect command-line parameters were used.

   3 - A write error has occurred.

These values will be most useful when writing bash scripts. But even at the command prompt, we can demonstrate how to execute the command as long as you're working in a terminal window (TTY or PTS session).

tty -s && echo "In a tty"

 

Note: The operator is a logical operator and. If the command line contains , then it is executed only if the exit status of the command is , which indicates its successful completion.&&command1 && command2command2command10

As we are working in a TTY session, our exit code is (success) and the second command is executed.0

Who command


There are also other commands that can display your TTY number. The who command displays information about all logged-on users, including you.

The following screenshot shows that the diego user is connected to the Linux computer. The part is a screen and keyboard physically connected to a computer. Even though the screen and keyboard are hardware devices, they are still connected to the multiplexer via the /dev/pts/1 device file.:0

Accessing TTY

You can access a full-screen TTY session by holding down Ctrl+Alt and pressing one of the function keys.

Pressing Ctrl+Alt+F3 will prompt you to log in to tty3.

 

If you log in and run the command, you will see that you are connected to /dev/tty3.tty

This is not a pseudo-teletype (emulated by software); it is a virtual teletype (emulated by hardware). It uses a screen and keyboard connected to your computer to emulate a virtual teletype, just like the DEC VT100 did.

You can use the Ctrl+Alt key combination with the F3-F6 function keys to open the appropriate TTY sessions. For example, you can enter tty3 and press Ctrl+Alt+F6 to go to tty6.

To return to the graphical desktop environment, press Ctrl+Alt+F2. Pressing Ctrl+Alt+F1 will take you back to the graphical desktop session login screen.

The following keyboard shortcuts have been tested on current versions of Debian, Manjaro, Ubuntu, and Fedora distributions:

   Ctrl+Alt+F1 - Returns you to the desktop graphical login screen.

   Ctrl+Alt+F2 - Returns you to the graphical desktop environment.

   Ctrl+Alt+F3 — opens tty3.

   Ctrl+Alt+F4 — opens tty4.

   Ctrl+Alt+F5 — opens tty5.

   Ctrl+Alt+F6 - Opens tty6.

Having access to these full-screen consoles allows people using a minimal Linux installation (and many Linux servers are set up that way) to have multiple consoles available.

Have you ever had a situation where while working on Linux something caused your session to hang? Now you can go to one of the TTY console sessions to try to fix the situation. You can use commands and to try to identify a failed application, then type a command to complete the process, or simply use it to try to shut down the system correctly.toppskillshutdown

Conclusion

The tty command, derived from the device of the late 1800s, appeared in UNIX in 1971. With the further development of computers, teletypes, and then video terminals, became a thing of the past. However, the subsystems for working with them, although they have undergone significant changes, have remained in the kernels of operating systems.