When using a *nix variant of one kind or another, you can press a certain key combination and be transported to another land. A land of magic. Or at least a fresh shell. If you’re using a GUI DE then pressing this certain key combination will take you from the land of pretty colors to a land of monochrome… unless you’ve gone all crazy with your bashrc file, but that’s for another post.
What is this strange key combination? It depends on your distribution, but it’s going to most likely be Alt-F1 (through F7) or Control-Alt-F1 (through F7). Before you go pounding that key combination, know that your desktop environment is likely on the F1 or F7 terminal. If you get whisked away from your sparkly world of windows and menus, but you want to come back, just press Control-Alt-F1/F7.
The concept is known as “Virtual Terminals” or “Virtual Consoles” and I suggest that if you’re not familiar with it, that you read up on it. Especially if you’re considering getting your RHCSA like some friends and I are. Oh, and make sure to check out the Stack Exchange thread of epic proportions titled “What is the exact difference between a ‘terminal’, a ‘shell’, a ‘tty’ and a ‘console’?” as well as the nearly-as-edifying Q/A “Why is a virtual terminal “virtual”, and what/why/where is the “real” terminal?”
Anyway, I use virtual terminals to have multiple commands running simultaneously but not in the background of a single shell (e.g. running top on virtual console 2 while I go back to frobbing on console 1). I find it easier to check the progress of a running program when it’s in a virtual console rather than as a background job in a single shell.
In the course of using virtual consoles, sometimes I want to know exactly where I am. Am I on vterminal 4? 6? How would one find that information out?
The answer is with the command tty. In fact, if you read the two Q/A session I linked to above, you’ll know exactly why the command is called `tty`. When you run that command, you’ll be told which terminal you’re on.
[user@computer ~]$ tty /dev/tty3
Now we know exactly where we are! You can also do some stupid tricks with virtual terminals since they are represented by device files in the Linux filesystem. For example, you can send output from one tty to another.
echo woot > /dev/tty3 would send the text “woot” onto the console located at tty3 (to be accessed with Alt-F3). I’m sure there’s a useful application for that ability, but I haven’t found it yet.
It should also be noted that if you want to see how many virtual terminals currently have someone logged in, the
who command can help you.
[user@computer ~]$ who wesley tty3 2012-10-13 12:13 snipes tty2 2012-10-13 12:13 crusher tty4 2012-10-13 12:14 borland tty1 2012-10-13 12:10 (:0)
Have any handy bits of wisdom for the use of virtual consoles? Want to share? Share with the class in the comments section.