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]...
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.
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.
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.
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.
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.
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
- The “time” Command in Linux [4 Practical Examples]
- The “uptime” Command in Linux [5 Practical Examples]
- The “vmstat” Command in Linux [6 Practical Examples]
- The “service” Command in Linux [6 Practical Examples]
- The “sestatus” Command in Linux [4 Practical Examples]
- The “shutdown” Command in Linux [7 Practical Examples]
FUNDAMENTALS A Complete Guide for Beginners
how to send some text using TTY ?
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.