How do I Know Which Virtual Terminal I’m Using in Linux?

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

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.



  1. xorpaul

    October 31, 2012 at 5:04 am

    I guess you already know about the w command, which shows more than who and is faster to type 😉
    You can also get the remote hostname from where the user logged in with w -f


  2. Mathew

    October 31, 2012 at 3:24 pm

    Another option, albeit not necessarily more efficient is to press Alt+{LR}-arrow. This will switch you between the virtual terminals in succession either forward (R-arrow) or backward (L-arrow). However, once you reach the GUI you have to press Ctrl+Alt+F{vtty#} again to get back to one of the other vttys. The Alt+{LR}-arrow trick doesn’t work with the GUI.


Leave a Reply

Follow TheNubbyAdmin!

follow us in feedly

Raw RSS Feed:

Contact Me!

Want to hire me as a consultant? Have a job you think I might be interested in? Drop me a line:

Contact Me!

Subscribe via Email

Your email address is handled by Google FeedBurner and never spammed!

The Nubby Archives

Circle Me on Google+!

Photos from Flickr

Me on StackExchange

The IT Crowd Strava Group

%d bloggers like this: