قالب وردپرس درنا توس
Home / Tips and Tricks / What is a TTY on Linux? (and using the tty command)

What is a TTY on Linux? (and using the tty command)



  Telegraph typewriter
June Marie Sobrito / Shutterstock.com

What does the command tty do? The name of the terminal used is printed. TTY stands for "Teletypewriter". What is the story behind the name of the command? That needs to be explained in more detail.

Remote Printers from the 1
800s

In the 1830s and 1840s, machines were developed that are known as remote printers. These machines could send typed messages "over the line" to remote locations. The messages were entered by the sender on a type of keyboard. They were printed on paper at the receiving end. They were an evolutionary step in telegraphy, previously based on Morse and similar codes.

Messages were encoded and sent, then received, decoded and printed. There were several techniques to encode and decode the messages. The most famous and one of the most productive was patented in 1874 by Émile Baudot, after whom the baud rate is named. Its character encoding scheme was 89 years older than ASCII.

The coding of Baudot eventually came closest to a standard in teletype coding and was adopted by most manufacturers. Baudot's original hardware design had only five buttons, much like piano keys. The operator had to learn a specific key combination for each letter. Finally, the Baudot coding system was coupled to a traditional keyboard layout.

To mark this development, the machines were called Teletypewriters. This has been shortened to teletypes and finally to TTYs. Hence the acronym TTY, but what does telegraphy have to do with computing?

ASCII and Telex

When ASCII arrived in 1963, it was taken over by teletype makers. Despite the invention and the widespread use of the phone, the teletypes were still prevalent.

Telex was a worldwide network of teletypes that sent written messages around the globe. They were the main means of transmitting written news in the post-World War II period to the boom of fax machines in the 1980s.

The computers continued to evolve. They have been able to interact with users in real time and to support multiple users. The old batch operation became inadequate. People did not want to wait 24 hours or longer for their results. Making stacks of punch cards and waiting for results overnight was no longer acceptable.

People needed a device to enter instructions and send the results back to them. People wanted efficiency.

Teletype converted

The Teletype was the perfect candidate as an input / output device. After all, it was a device that could input, encode, send, receive, decode, and print messages.

What did the teletype care if the device at the other end of the link was not another telegraph? As long as it spoke the same encoding language and could receive and return messages, the teletype was satisfied.

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

Hardware-Emulated Teletypes

Teletypes became the standard method for interacting with the big minis and mainframes of the time.

They were eventually replaced by devices that emulated those electromechanical machines used the electronics. These had instead of rolls of paper cathode ray tubes (CRTs). They did not wobble when they submitted answers from the computer. They enabled previously impossible functions such as moving the cursor on the screen, clearing the screen, bold, etc.

The DEC VT05 was an early example of a virtual telegraph and ancestor of the famous DEC VT100. Millions of DEC VT100 were sold.

Software-emulated Teletypes

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 console are examples of virtual teletypes. However, these are completely emulated in software. They are called pseudo-teletypes. This has been shortened to PTS.

And here comes tty into play.

What can tty tell us?

Under Linux, there is a pseudo-teletype multiplexer that manages the connections of all of the Terminal 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 at / dev / ptmx. [19659006[The tty command returns the name of the device file that your pseudo-teletype slave uses to interface to the master , And that's effectively the number of your terminal window.

Let's see what tty reports for our terminal window:

  tty 

  tty in a terminal window

The answer shows that we have the device file under / dev / pts

Our terminal window is a teletype software-emulation (TTY) type pseudo-teletype multiplexer connected to the Pseudo-Teletype (PTS) and isnumberedNull

The silent option

The option -s (silent) causes tty no output generated.

  tty -s 
  • tty-s in a terminal window "width =" 646 "height =" 77 "src =" /pagespeed_static/1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "/>

    However, an exit value is generated:

    • 0 : If the standard input is an emulated or physical one TTY device is from.
    • 1 : If the standard input is not from a TTY device.
    • 2 : Syntax error, wrong command line parameters used.
    • 3 : A write error has occurred. [19659042] This is probably the most useful for bash scripts. But even on the command line, we can show how a command is executed only when executed in a terminal window (a TTY or a PTS session).

        tty -s && echo "In a tty" [19659044] tty -s && echo "In a tty" in a terminal window "width =" 646 "height =" 57 "src =" / pagespeed_static / 1.JiBnMqyl6S .gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "/> 

      Since we're running in a TTY session, is our exit code 0.

      The who command

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

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

      User Dave appears as connected to ": 0".

      This represents the screen and keyboard physically connected to the computer. Although the screen and keyboard are hardware devices, they are connected to the multiplexer via a device file. tty reveals that there is /dev/pts/2.[19659029<who[19659052<tty[19659053<whoundtytheinaterminalwindow"width="644"height="165"src="/pagespeed_static/1JiBnMqyl6Sgif"onload="pagespeedlazyLoadImagesloadIfVisibleAndMaybeBeacon(this);"onerror="thisonerror=null;pagespeedlazyLoadImagesloadIfVisibleAndMaybeBeacon(this);"/>

      CONNECTED: How To Determine The current user account on Linux

      Accessing a TTY

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

      Ctrl + Alt + F3 calls the login request from tty3.

       tty3 console

      If you log in and enter the tty command, you will be connected to / dev / tty3 by then. [19659006<Thisisnotapseudo-teletype(software-emulated)Itisavirtual-type(in-the-hardware-emulated)typeofcomputer-interfacedscreenandkeyboarddesignedtosimulatevirtualteletypeasusedintheDETECVT100

      You can use the Ctrl + Alt function keys with the F3 through F6 function keys and open four TTY sessions as needed. For example, you might be logged in to tty3 and press Ctrl + Alt + F6 to switch to tty6.

       tty6 console "width =" 610 "height =" 150 "src =" / pagespeed_static / 1.JiBnMqyl6S. gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

      Press on your desktop to go back + Alt + F2.

      Pressing Ctrl + Alt + F1 returns you to the login prompt of your graphical desktop session Full screen TTY consoles and Ctrl + Alt + F7 return you to your desktop graphical environment. If you are using an older Linux distribution, your system may behave as follows.

      This has been tested in current versions of Manjaro, Ubuntu, and Fedora, and all have behaved as follows:

      1. Ctrl + Alt + F1 : Returns to the graphical desktop environment login screen ,
      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. [19659036] Ctrl + Alt + F6 : Opens TTY 6.

      By accessing these full-screen consoles, users who install Linux only from the command line - and many Linux servers are configured this way - have multiple consoles available to have.

      Ever worked on a Linux computer with a graphical desktop environment and did something freeze your session? Now you can go to one of the TTY console sessions to try to correct the situation.

      You can try top and ps to identify the failed application Then use kill to finish it, or just use shutdown to try to shut down the system as the computer will allow.

      RELATED: ] To terminate processes from the Linux terminal

      Three small letters with much history

      The command tty was after a device from the late 1800s, named in 1971 in Unix and is still part of Linux and Unix-like operating systems.

      The little guy has a lot of history behind him.


  • Source link