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.
will free all ressources connected to unused VTs.