GNU Screen is a versatile terminal multiplexer that enables you to manage multiple terminal sessions within a single window. It's particularly useful for running multiple processes simultaneously and keeping your terminal sessions active even when disconnected.
Installing screen
To install screen
on Ubuntu and Debian systems, execute the following command:
sudo apt install screen
Note: For Ubuntu versions 14.04 and earlier, use apt-get
instead of apt
.
To install screen
on CentOS and Fedora systems, run the command:
yum install screen
Using screen
To start screen
and open a new virtual terminal, enter the following command in your terminal:
screen
This will display the introductory information about screen
. Press Enter
to proceed to the virtual terminal. Your terminal will now switch to the new virtual session, hiding the original terminal window.
Commands in screen
The screen
utility offers a variety of commands to manage virtual terminals efficiently. These commands are typically invoked using key combinations.
The primary key combination for screen
commands is Ctrl + a
. After pressing these keys, you can enter additional commands.
Note: When you press Ctrl + a
, screen
waits for the next command without displaying a prompt. The commands you type afterward are not shown on the terminal.
Creating a new window: Press Ctrl + a
then c
to create a new terminal window within screen
.
Listing all windows: Press Ctrl + a
then "
to display a list of all open screen sessions. Use the arrow keys to navigate and press Enter
to select a session.
Switching to a specific window by name: Press Ctrl + a
then '
to prompt for a terminal identifier or name, and switch to it.
Switching to a window by number: Press Ctrl + a
then a number between 0
and 9
to switch to a corresponding terminal window.
Naming the current window: Press Ctrl + a
then A
to set a custom title for the current terminal window.
Detaching from a session: Press Ctrl + a
then d
to detach the current terminal from screen
. The processes in the detached session will continue running in the background.
Reattaching to a session: To reattach to a detached session, use the command:
screen -r
If you have multiple detached sessions, this command will list them and prompt you to select one to reattach.
Note: This command is entered in the terminal shell, not within a screen
session.
Detaching and logging out: Press Ctrl + a
then D
(uppercase) to detach the session and log out.
Viewing information about the current window: Press Ctrl + a
then i
to display information about the current terminal window.
Starting a log of the session: Press Ctrl + a
then H
to start logging the output of the current session to a file.
Exiting a virtual terminal: To exit the virtual terminal, press Ctrl + D
. This will close the current window. If it's the last window in the session, it will terminate the screen
session.
The screen
utility offers many other commands and features. To explore all the options available, consult the manual page by running:
man screen
🍻 Cheers!
Member discussion