
openvt Command in Linux
The openvt command in Linux starts a program in a new virtual terminal (VT). It finds the first available VT and runs the specified command with its options, redirecting input, output, and error to that terminal. If no command is provided, it defaults to the $SHELL environment variable.
Table of Contents
Here is a comprehensive guide to the options available with the openvt command −
Note − The openvt is designed to work with virtual consoles (Ctrl+Alt+F1 to F6) and not terminal emulators like GNOME Terminal, Konsole, or xterm. To use openvt, switch to a text-based virtual console by pressing Ctrl+Alt+F3 (or another F-key between F1-F6). Log in and run the command there.
Syntax of openvt Command
The syntax of the openvt command is as follows −
openvt [options] [command]
The [options] field is used to specify various options such as VT number and others to change the command's behavior. The [command] field is used to specify commands and options to be executed in the specified virtual terminal.
openvt Command Options
The options for openvt command are listed below −
Flags | Options | Description |
---|---|---|
-ct vtnumber | --console= vtnumber | Use the specified VT (requires write access) |
-f | --force | Force use of a VT, even if already in use |
-e | --exec | Execute the command directly, without forking (for /etc/inittab) |
-s | --switch | Switch to the new VT and make it active |
-u | --user | Run login as the current VT's owner (for init; not with -c or -l) |
-l | --login | Start the command as a login shell (adds - to the command name) |
-v | --verbose | Enable verbose output |
-w | --wait | Wait for the command to complete; with -s, switch back afterward |
-V | --version | Display command version |
-h | --help | Display help about the command |
Examples of openvt Command in Linux
This section shows the usage of the openvt command in Linux with examples −
Running a Command in Virtual Terminal
To execute a command in the next available virtual terminal simply run the openvt command without any option −
sudo openvt dmesg
To execute a command in virtual terminal 3 (VT 3), use the -c or --console option with the virtual terminal number. For example, to run the top command in virtual terminal 3, use the following command −
sudo openvt -c 4 top

To switch to virtual terminal 4, press Ctrl+Alt+F4.

To exit the virtual terminal press Ctrl+D.
Running a Command in a Busy Virtual Terminal
If a virtual terminal is already running a command, openvt will throw an error as shown below −

To forcefully run a command in a busy virtual terminal, use the -f or --force option −
sudo openvt -f -c 4 htop

Running a Command and Switching to a Specified Virtual Terminal
By default, the openvt command executes without producing any output. The virtual terminal needs to be switched to view the output of the executed command. To execute and switch the virtual terminal, use the -s or --switch option −
sudo openvt -c 4 -s htop

On executing the above command, the virtual terminal will immediately be switched to the specified terminal.
Switching Back to Virtual Terminal After Completing the Executed Command Process
By default, the openvt runs the command in the terminal. To switch back after completing the process to the original terminal, use the following command −
sudo openvt -c 5 -s -w vim
If virtual terminal 5 is not busy, the above command will switch to virtual terminal 5 and open the Vim editor. Once the editor is closed, the system will switch back to the original virtual terminal where the command was executed.
Getting Verbose Output
By default, the openvt does not produce in which terminal command is going to execute. To display the terminal name, use the -v or --verbose option −
sudo openvt -v -c 7 htop

Displaying Help
To display help about the command, use the -h or --help options −
openvt -h
Conclusion
The openvt command in Linux is a versatile tool for running programs in virtual terminals, providing options for selecting specific terminals, switching between them, and controlling command execution. This command is particularly useful for managing tasks in text-based virtual consoles (Ctrl+Alt+F1 to F6) rather than GUI-based terminal emulators.
In this tutorial, we covered the openvt command, its syntax, options, and usage in Linux with examples.