In Linux you have multiple virtual terminals which you usually navigate using the [Ctrl] + [Alt] + [Fn] key. [Fn] stands for F1 to F12 keys.

But the same thing can be achieved by using a little command in Linux called chvt.

chvt command stands for CHange Virtual Terminal. It takes one option which is a number which tells it the virtual terminal to switch to.

For example, if you are logged in at the first virtual terminal and you want to switch to the 7th where the xserver usually displays the GUI, then run the chvt as follows :

$ chvt 7

And to return to the 1st virtual terminal, type :

$ chvt 1

Suppose you have Imagemagick installed on your Linux machine and you wish to take a screenshot of your GUI while you are logged in at the console. Here is a simple way of doing it :

$ chvt 7; sleep 2; import -display :0.0 -window root screenshot-output.png; chvt 1;

What this does is, it first moves to virtual terminal 7, sleeps for 2 seconds, then use the import command to capture the screenshot of the desktop and save it in the file screenshot-output.png, and finally return back to virtual terminal 1 which was your original console. Cool isn’t it ?

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.