What is a TTY on Linux? (and How to Use the tty Command)

Typewriter for teleprinterJune Marie Sobrito / Shutterstock.com

What does the tty command do? It prints the name of the terminal you are using. ATS stands for "teletypewriter". What is the story behind the name of the order? It takes a little more explanation.

The teleprinters of the 1800s

In the 1830s and 1840s, machines known as teleprinter have been developed. These machines could send typed messages "on the wire" to remote locations. The messages were typed by the sender on some kind of keyboard. They were printed on paper at the reception. They have been a stage of evolution in telegraphy, who previously relied on Walrus and similar codes.

The messages were coded and transmitted, then received, decoded and printed. Several techniques have been used to code and decode messages. The most famous and one of the most prolific was patented in 1874 by Emile Baudot, for whom baud rate is called. His pre-dated character encoding scheme ASCII by 89 years old.

Baudot's coding has finally become the closest thing to a teletype coding standard, and it has been adopted by most manufacturers. The original material design of Baudot had only five keys, similar to the piano keys. The operator had to learn a particular key combination for each letter. Finally, the Baudot coding system was coupled to a traditional keyboard layout.

To mark this progress, the machines were called teletypewriters. This has been reduced to teletypes and eventually to ATS. So that's where we get the acronym ATS's, but what does telegraphy have to do with computer science?

ASCII and telex

When ASCII arrived in 1963, it was adopted by the ticker manufacturers. Despite the invention and the widespread use of the telephone, teletypes were still very active.

Telex was a global network of teletypes for sending written messages around the world. It is the main means of transmitting written messages in the period following the Second World War to the fax boom of the 1980s.

Computers were evolving too. They were able to interact with users in real time and support multiple users. The old method of batch work has become insufficient. People did not want to wait 24 hours or more to get their results. Making piles of punch cards and waiting for results all night was no longer acceptable.

People needed a device to enter instructions and receive the results. People wanted efficiency.

The reused teletype

Teletype was the ideal candidate as an input / output device. After all, it was a device designed to allow you to type, encode, send, receive, decode and print messages.

What was teletype doing if the device at the other end of the connection was not another teletype? As long as it speaks the same encoding language and can receive messages and return messages, the teletype is satisfied.

And of course, he used a more or less standard keyboard.

Materialized teletypes

Teletypes have become the default way of interaction with the large mini and grand system computers of this era.

They were eventually replaced by devices emulating these electro-mechanical machines using electronics. These had Cathode ray tubes (CRT) instead of paper rolls. They did not shiver when they answered the computer. They allowed for features up to now impossible, such as moving the cursor on the screen, clearing the screen, putting bold text, and so on.

the DEC VT05 was one of the first examples of virtual teletype and an ancestor of the famous DEC VT100. Millions of DEC VT100s have been sold.

Teletype Software

In the Linux desktop environment and other Unix-like operating systems such as macOS, the terminal window and applications such as term x and Konsole are examples of virtual teletypes. But these are fully imitated by software. They call themselves pseudo-teletypes. This has been reduced to PTS.

And that's where tty comes in.

What can tty tell us?

Under Linux, there is a pseudo-teletype multiplexer that manages connections from all terminal window pseudo-teletypes (PTS). The multiplexer is the master and the PTS are the slaves. The multiplexer is addressed by the kernel via the device file located in / dev / ptmx.

The tty command will print the name of the device file used by your pseudo-teletype slave for the interface to the master. And that's the number of your terminal window.

Let's see what tty is reporting for our terminal window:

tty

tty in a terminal window

The answer shows that we are connected to the device file at / dev / pts / 0.

Our terminal window, which is a Teletype (TTY) software emulation, is interfaced to the pseudo-teletype multiplexer as a pseudo-teletype (PTS). And it happens to be the number zero.

The silent option

The -s (silent) option prevents tty from generating an output.

tty -s

tty -s in a terminal window

This produces an output value, however:

0: if the standard input comes from a TTY device, emulated or physical.
1: if the standard input does not come from a TTY device.
2: Syntax error, incorrect command line parameters were used.
3: A writing error has occurred.

This will probably be more useful in Bash scripts. But, even on the command line, we can show how to execute a command only if you are running a terminal window (a TTY or PTS session).

tty -s && echo "In a tty"

Since we are running a TTY session, our exit code is 0 and the second command is executed.

The order

Other orders may reveal your TTY number. The who command lists information for all connected users, including yourself.

Alec and Mary are remotely connected to the Linux computer. They are connected to PTS one and two.

User dave appears as connected to ": 0".

This represents the screen and the keyboard physically connected to the computer. Although the display and keyboard are hardware devices, they are still connected to the multiplexer via a device file. tty reveals that it's about / dev / pts / 2.

who
tty

who and tty in a terminal window

RELATED: How to determine the current user account on Linux

Access an ATS

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

Ctrl + Alt + F3 will bring up the tty3 login prompt.

tty3 console

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

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

You can use the Ctrl + Alt softkeys with the F3 to F6 softkeys and open four TTY sessions if you wish. For example, you can connect to tty3 and press Ctrl + Alt + F6 to access tty6.

tty6 console

To return to your graphical desktop environment, press Ctrl + Alt + F2.

Press Ctrl + Alt + F1 to return to the login prompt for your graphical session.

At one point, Ctrl + Alt + F1 to Ctrl + Alt + F6 opened the full-screen TTY consoles and Ctrl + Alt + F7 would take you back to your graphical desktop environment. If you are using an older Linux distribution, your system might behave this way.

This has been tested on the current versions of Manjaro, Ubuntu and Fedora and they all behaved as follows:

Ctrl + Alt + F1: takes you back to the login screen to the graphical desktop environment.
Ctrl + Alt + F2: takes you back to the graphical desktop environment.
Ctrl + Alt + F3: Opens the ATS 3.
Ctrl + Alt + F4: Open the ATS 4.
Ctrl + Alt + F5: Opens the ATS 5.
Ctrl + Alt + F6: Opens the ATS 6.

Access to these full-screen consoles allows people using Linux installations only from the command line (and many Linux servers are configured this way) to have multiple consoles.

Have you ever worked on a Linux machine with a graphical desktop environment and your session is frozen? You can now access any of the TTY console sessions to try to remedy the situation.

You can use top and ps to try to identify the failed application, then use kill to finish it, or just use shutdown to try to close as smoothly as the status of the application allows. # 39; s computer.

RELATED: How to kill Linux terminal processes

Three small letters with a lot of history

The tty command takes its name from a late nineteenth century device, first appeared in Unix in 1971 and is part of Linux and Unix-like operating systems to this day.

The little guy has a story behind him.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.