- Unix Commands Reference
- Unix Commands - Home
fgconsole Command in Linux
The fgconsole command on Linux displays the number of the currently active virtual terminal (VT). The virtual terminal is a Linux feature that allows access to a system through a text-based interface. It is also known as a virtual console (VC). It allows a user to access the shell and interact with the operating system. In Linux, it is termed as tty or teletype due to its functional resemblance with earlier teletypes.
Table of Contents
Here is a comprehensive guide to the options available with the fgconsole command −
- Syntax of fgconsole Command
- Options of fgconsole Command
- Understanding Linux Virtual Terminals
- Examples of fgconsole Command in Linux
Syntax of fgconsole Command
The syntax of the Linux fgconsole command is as follows −
fgconsole [options]
The [options] field is used to specify the options to modify the behavior of the command.
Options of fgconsole Command
The options used with the Linux fgconsole command are listed below −
Options | Description |
---|---|
-C (--console)=DEV | It is used to specify the device name to be used for output |
-h (--help) | It is used to display help related to command |
-n (--next-available) | It is used to print the number of the next unallocated virtual terminal |
-V (--version) | It is used to display the command version |
Understanding Linux Virtual Terminals
If you are using Linux with a desktop environment, then you may not be able to use the fgconsole command from the terminal app. It is designed to work on virtual consoles, not on console emulators.
To access a virtual terminal on a Linux desktop environment, use ctrl+alt+F2 to F6. If you press ctrl+alt+F3, the third virtual terminal will open.
Similarly, to open the fourth virtual terminal use ctrl+alt+F4.
Typically, 6 virtual terminals can be accessed on a Linux system. However, the total number of virtual terminals available can be configured up to 63, depending on the kernel settings.
To exit the virtual terminal and return to the graphical environment use ctrl+alt+F1 or ctrl+alt+F7.
To list the currently active virtual terminals, use the w command −
Examples of fgconsole Command in Linux
This section demonstrates the usage of the fgconsole command in Linux with examples −
- Displaying the Current Virtual Terminal Number
- Displaying the Next Unallocated Virtual Terminal
- Displaying the Active Virtual Terminal Number of a Specific Device
- Displaying Help
Displaying the Current Virtual Terminal Number
To display the current virtual terminal number, execute the fgconsole command without any option −
fgconsole
Displaying the Next Unallocated Virtual Terminal
To display the next unallocated virtual terminal, use the -n or --next-available option. This option is used to find the VT available for the new session.
fgconsole -n
Displaying the Active Virtual Terminal Number of a Specific Device
To display the currently active virtual terminal number for a specific device, use the -C or --console option −
fgconsole -C /dev/tty4
The output is 3 which indicates that virtual terminal 3 is currently active for device /dev/tty4.
Displaying Help
To print the help of the fgconsole command, use the -h or --help option −
fgconsole -h
Conclusion
The fgconsole command in Linux is used to print the number of currently active virtual consoles. For example, if the virtual terminal is "/dev/tty3", it will display 3 to the standard output. Displaying the virtual terminal number can be useful for system administrators to manage the virtual terminal sessions.
In this tutorial, we explained the fgconsole command, its syntax, options, and usage in Linux through various examples.