The “tty” Command in Linux [4 Practical Examples]

The tty command determines the terminal or terminal-like device associated with a process. Here tty stands for teletype and represents the used devices of the early computer systems. In this article, I will demonstrate to you the ins and outs of the tty command in Linux.

A. Description

The tty command is very useful in determining the terminal associated with a process and can be used to differentiate between an interactive prompt and a non-interactive prompt. Additionally, tty command can also check the device associated with a specific process, which can be really useful.

B. Syntax

The syntax of tty command is pretty simple in Linux. And the syntax is given below:

tty [OPTION]...
Note: In the syntax above, OPTION enclosed by a square bracket followed by 3 dots represents that more than one option can be used at the same time.

C. Options

There are a few options available for the tty command in Linux. You can see the options of the command are mentioned here. However, you can look for the tty command on the man page to know more about its options.

man tty

Useful Options

  • -s, does not print anything.
  • –version, displays version information.
Note: The options in Linux CLI (Command Line Interface) are case-sensitive, so be cautious when you use them.

Practical Examples of the “tty” Command in Linux

The tty command is used to display information regarding the terminal. You will learn some practical examples of the tty command in Linux here.

Example 1: Check the Terminal Device Using the “tty” Command in Linux

You can check the terminal device using the tty command in Linux. Here I am checking the terminal device with the help of tty command. To do the same you can follow the instructions below:

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ To check the terminal device, execute the following command in the command prompt:

tty

➌ Now, press the ENTER button.

Output >

In the image below, the output shows the terminal device.Check the Terminal Device

Example 2: List Different tty Devices Using the “ls” & the “grep” Command

The different tty devices can be listed using the ls & grep command. Here I am listing the different tty devices. You can also do the same by following the process below:

Steps to Follow >

➊ To initiate, launch the Ubuntu Terminal.

➋ To list the different tty devices, run the command below in the command prompt:

ls -l /dev | grep 'tty'

➌ Then, tap the ENTER button.

Output >

In the following image, the output shows the list of different tty devices.List Different tty Devices Using the “ls” & “grep” Command

Example 3: View the Active tty Devices Using the “cat” Command

You can view the active tty devices using the cat command in Linux. Here I will display the active tty devices with the help of the cat command. To do this you can follow the given procedure:

Steps to Follow >

➊ Start by opening the Ubuntu Terminal.

➋ To view the active tty devices, type the following command in the command prompt:

cat /proc/tty/drivers

➌ Finally, hit the ENTER key.

Output >

As you can see in the image below, the output displays the active tty devices.View the Active tty Devices Using the “cat” Command

Example 4: Display the Version Using the “tty” Command in Linux

You can use the tty command to display the version of the system. I will display the version using the tty command in Linux. You can also do this by following the steps below:

Steps to Follow >

➊ Initially open the Terminal in Ubuntu.

➋ Then, Copy the command below in the command prompt:

tty --version

➌ Now, strike the ENTER key.

Output >

Finally, in the below image, I can see the version of my system on the display.Display the Version

Conclusion

As you have seen in this article, the tty command has a few uses in Linux. Eventually, you’ve also learned the syntax, some functional options, and the practical application of this command. To become an expert in Linux, try practical applications of this command by yourself.


Similar Readings

5/5 - (1 vote)
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
Jannatul Ferdousi Sylvie

Hi there! This is Jannatul Ferdousi Sylvie. I am one of the Linux Content Developer Executives at Softeko. I live in Dhaka, Bangladesh. I have completed my BSc. in Software Engineering from American International University-Bangladesh. You can see my projects in the GitHub account. I love traveling, shopping, cooking, and gardening. Read Full Bio

2 thoughts on “The “tty” Command in Linux [4 Practical Examples]”

    • Hello A. Nonymous,
      To send text using TTY, you can use the echo command followed by the text you want to send, and then redirect it to the appropriate TTY device. For example:
      echo "Your text here" > /dev/ttyX
      The “X” in ttyX needs to be replaced with the actual number of the specific tty device you want to send the text to. You can find out which ttyX corresponds to your current terminal by running the tty command. However, this only sends the text itself, not any special characters or acts like user input.
      Thanks for your query.

      Reply

Leave a Comment