What is a TTY in Linux? (and how to use the tty command)

What does the tty Command do? It prints out the name of the terminal you are using. TTY stands for “Teletype”. What’s the story behind the name of the command? That needs a little more explanation.

Telegraph from the 19th century

In the 1830s and 1840s machines were known as the Teletype was developed. These machines could send typed messages “over the wire” to distant locations. The messages were entered by the sender on a kind of keyboard. They were printed on paper on the receiving side. You were an evolutionary step in telegraphythat had previously relied on Morse and similar codes.

Messages were encrypted and transmitted, then received, decrypted, and printed. There were several techniques that were used to encrypt and decode the messages. The most famous and one of the most productive was patented by in 1874 Emile Baudotfor whom the baud rate named. Its character encoding scheme is outdated ASCII by 89 years.

Baudot’s coding eventually became the closest to a standard in teletype coding and was adopted by most manufacturers. Baudot’s original hardware design only had five keys, similar to piano keys. The operator had to learn a specific key combination for each letter. Eventually the Baudot coding system was coupled to a traditional keyboard layout.

To mark this advance, the machines were called teleprinters. This was shortened to Teletypes, and eventually TTYs. Here we get that acronym TTY from, but what does telegraph have to do with computers?

ASCII and Telex

When ASCII arrived in 1963, it was adopted by the teletype manufacturers. Despite the invention and widespread use of the phone, teletypes were still going strong.

telex was a worldwide network of teletypes that made it possible to send written messages around the globe. In the period after the Second World War until the 19th Fax machine boom 1980s.

Computers also evolved. You became able to interact with users in real time and support multiple users. The old batch method became inadequate. People didn’t want to wait 24 hours or more for their results. Making stacks of punch cards and waiting for results overnight was no longer acceptable.

People needed a device that they could use to enter instructions and send back the results. People wanted efficiency.

The repurposed teleprinter

The teletype was the perfect candidate as an input / output device. It was, after all, a device that made it possible to type, encrypt, send, receive, decrypt, and print messages.

What did the teletype care if the device on the other end of the line wasn’t another teletype? As long as it spoke the same encryption language and could receive and send messages back, the teletypewriter was happy.

And of course a more or less standard keyboard was used.

Hardware emulated teleprinter

Teletypewriters became the standard means of interacting with the large mini and mainframe computers of the time.

They were eventually replaced by devices that emulated these electromechanical machines with electronics. These had Cathode ray tubes (CRTs) instead of paper rolls. They didn’t tremble when they responded to the computer. They enabled previously impossible functions such as moving the cursor around the screen, clearing the screen, bold font and so on.

the DEC VT05 was an earlier one example a virtual teletypewriter and an ancestor of the famous DEC VT100. Millions of DEC VT100 have been sold.

Software emulated teleprinter

In the desktop environment of Linux and other Unix-like operating systems such as macOS, the terminal window and applications such as x term and Consoles are examples of virtual teleprinters. However, these are fully emulated in software. They are called pseudo-teletypes. This has been shortened to PTS.

And that’s where tty come in.

What can you tell us

Linux has a pseudo-teletype multiplexer that processes the connections from all pseudo-teletypes (PTS) of the terminal window. The multiplexer is the master and the PTS are the slaves. The multiplexer is addressed by the kernel via the device file under / dev / ptmx.

the tty Command outputs the name of the device file that your pseudo teletype slave uses to connect to the master. And that is effectively your terminal window number.

Let’s see what tty Reports for our terminal window:


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

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

The silent option

the -s (silent) option tty produce no output.

tty -s

However, it creates one Exit-Value:

  • 0: if the standard input comes from a TTY device, emulated or physical.
  • 1: if the standard input is not from a TTY device.
  • 2: Syntax error, wrong command line parameters were used.
  • 3: A typographical error has occurred.

This is probably most useful when scripting bash. But even on the command line, we can demonstrate how a command will only run when run in a Terminal window (a TTY or PTS session).

tty -s && echo "In a tty"

Since we are running in a TTY session, ours is Exit-Code 0 and the second command is executed.

The who command

Other commands can show your TTY number. the who The command lists information for all logged-in users, including yourself.

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

User dave is shown as connected with “: 0”.

This represents the screen and keyboard that are physically connected to the computer. Although the screen and keyboard are hardware devices, they are still connected to the multiplexer through a device file. tty indicates that it is / dev / pts / 2.


How to determine the current user account on Linux

Access a TTY

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

Ctrl + Alt + F3 opens the tty3 login prompt.

tty3 console

When you log in and the tty Command you will see that you are connected to / dev / tty3.

This is not a pseudo teletype (emulated in software); it is a virtual teletype (emulated in hardware). It uses the screen and keyboard connected to your computer to emulate a virtual teletype, as the DEC VT100 used to do.

You can use the Ctrl + Alt function keys with the F3 through F6 function keys and have four TTY sessions open if you want. To the example, you could log into tty3 and hit Ctrl + Alt + F6 to get to tty6.

tty6 console

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

Pressing Ctrl + Alt + F1 will return you to the login prompt of your graphical desktop session.

All of a sudden, Ctrl + Alt + F1 through Ctrl + Alt + F6 would open the full screen TTY consoles, and Ctrl + Alt + F7 brings you back to your graphical desktop environment. If you’re using an older Linux distribution, your system may behave like this.

This has been tested on current versions of Manjaro, Ubuntu and Fedora and they all acted like this:

  1. Ctrl + Alt + F1: Returns to the login screen of the graphical desktop environment.
  2. Ctrl + Alt + F2: Returns to the graphical desktop environment.
  3. Ctrl + Alt + F3: Opens TTY 3.
  4. Ctrl + Alt + F4: Opens TTY 4.
  5. Ctrl + Alt + F5: Opens TTY 5.
  6. Ctrl + Alt + F6: Opens TTY 6.

Access to these full-screen consoles allows users who only use Linux installations from the command line – and many Linux servers are configured this way – to have multiple consoles available.

Have you ever worked on a Linux machine with a graphical desktop environment and something caused your session to freeze? Now you can switch to one of the TTY console sessions to try to resolve the situation.

You can use top and ps to try to identify the failed application, and then use kill to finish it or just use it shutdown try something close Shut down as gracefully as the state of the computer allows.

How to end processes from the Linux terminal

Three little letters with a lot of history

the tty Command takes its name from a device from the late 19th century, appeared in Unix in 1971, and is still part of Linux and Unix-like operating systems to this day.

The little guy has a whole story behind him.

Linux commands
Filestar · pv · cat · tac · chmod · grep · difference · sed · With · man · pushed · popd · fsck · Test disk · seq · fd · pandoc · CD · $ PATH · awk · join · jq · wrinkles · unique · Journalctl · tail · stat · ls · fstab · echo · fewer · chgrp · chown · rev · look · Strings · Type · rename · Postal code · unzip · assemble · ummount · To install · fdisk · mkfs · rm · rmdir · rsync · df · gpg · weather · Nano · mkdir · from · ln · Patch · Convert · rclon · Scraps · srm
Processesalias · screen · above · kind · renice · progress · strace · system · tmux · chsh · story · at · Batch · for free · which · dmesg · chfn · User mod · ps · chroot · xargs · tty · pinkie finger · lsof · vmstat · Time out · Wall · Yes sir · kill · sleep · sudo · it is · Time · groupadd · User mod · groups · lshw · switch off · start anew · Stop · switch off · passwd · lscpu · crontab · date · bg · fg
Networkingnetstat · Ring · Trace route · ip · ss · who is · fail2ban · bmon · she · finger · nmap · ftp · curl · wget · who · who am I · w · iptables · ssh-keygen · ufw

Best Linux Laptops for Developers and Enthusiasts

Related Posts