Linux : Taking control of Virtual Terminals (VT) from command line

When you use Linux in text mode (as opposed to with an X server), you readily have access to multiple Virtual Terminals (aka VT for short) by hitting one of your <Alt-Fn> keys (if you are running a X server, you’ll need to hit <Ctrl-Alt-Fn> simultaneously).

This lets you access one of the VTs which are initialized at boot time, but won’t let you create new ones even if your kernel configuration would allow more VTs. Furthermore, what if you want to deal with VTs from a script ?

This post covers the 3 commands which will let you control your VTs from the command line or from a script.

Creating a VT with openvt

openvt will scan for a free VT and let you start a command onto it. The -s option will make openvt switch the screen to this VT.

Check out the man page for the other options (such as -w to wait for the end of the program, -s to switch to the newly created VT etc).
spaghetti:~$ openvt -s bash
will start and run bash in a new VT, and switch the display to this VT.

Switching VTs with chvt

This command will let you switch to any VT, existing or not. If the VT doesn’t exist yet, it will be allocated on the fly.
spaghetti:~$ chvt 5
will switch the screen to the 5th VT (and create it if needed).

Getting rid of unused VTs with deallocvt

The 2 previous commands will let you create VT and switch to them but will not deallocate them once the program running on it terminates.
So last but not least, the deallocvt command will exactly do this. It will release the resources allocated to the unused specified VT or to any unused VT if none specified.
spaghetti:~$ deallocvt
will free all ressources connected to unused VTs.

2 thoughts on “Linux : Taking control of Virtual Terminals (VT) from command line”

  1. Using the commands mentioned here (openvt and chvt specifically), I have come one step closer to my CLI multi-head goals: I successfully launched the command “open -f -c 1 — man open” over ssh to run “man open” on my remote console, but what seems to be missing is a way to send “q” to that vt to close the “man” program. With all the GUI power-users in the world, I almost didn’t find this post at all (found openvt using “man -k vt” and started Googling for the rest of the toolkit) and expect the road to sending keystrokes equally blocked in this way. (Its always nice to learn that I’m not as crazy as people say.)

Comments are closed.