Linux screen provides users an option to open several separate terminal instances within a single terminal window manager. Screen also includes an enhanced command line, giving you extra features and functionality over a standard command line.
This tutorial will show you how to install and use Screen on a Linux system.
- A user account with sudo privileges
- Access to a command line / terminal window (Ctrl+Alt+T/Ctrl+Alt+F2)
How to Install Screen on Linux
If you’re running a recent version of Linux, like Ubuntu 18.04 or CentOS 7, you probably already have Screen installed.
To verity if screen is installed, check the version with the command:
Installing Screen on CentOS
To install Screen on Red Hat / CentOS, enter the command:
yum install screen
Installing Screen on Debian or Ubuntu
To install screen on Debian/Ubuntu, enter the following:
sudo apt-get install screen
Commands to Start Screen
To launch Screen, enter the following at a command line:
The tool will launch and give you a brief license agreement. Press the spacebar or Enter to continue to the Screen shell. The system will drop out to a command line that looks just like a regular terminal window.
Screen works using command keystrokes. These are usually Ctrl-a plus another key.
To display a list of available commands, enter the following:
When you launch the Screen application, it’s helpful to name the session. This helps you keep track of different instances.
To name a session with the –S option:
screen –S name_session
To exit Screen, use the following command:
Note: Press and release the ctrl-a key combination, then hold the shift key and press the ? key.
Basic Commands in Screen to Manage Windows
When Screen is first launched, it creates one window inside of the Screen session. New windows can be created and switched using command keystrokes.
To open a new Screen window, use the following keystroke:
The original window is labeled 0 bash, unless you name it something different. Each new Screen window gets a number, up to 9.
Here is a list of useful commands for managing Screen windows:
Ctrl-a c –
Create a new window
– List all open windows
0 – Switch to window #0 (or any other numbered window)
– Rename the current window
– Split the screen horizontally, with the current window on top
– (pipe) Split the screen vertically, with the current window to the left
– Switch between areas of the split screen (usually used along with
to run different windows side-by-side)
– Switch between current and previous windows
– Switch to the next window
– switch to the previous window
– Quit all other windows except the current one
– Lock the current window
– Create a running log of the session
– Monitor a window for output (Screen will flash a notification when that window has activity)
– (underscore) Watch the window for the absence of output (such as when a file finishes downloading, or a compiler finishes)
– kill the Screen session (or you can type exit)
Detaching From Screen
You can leave a process working in Screen, and exit the interface. This is the equivalent of minimizing an application in a graphical operating system.
To detach from screen (and leave the window running in the background):
Reattach to Screen
Screen helps preserve your work if your remote SSH connection drops.
To reconnect to the server, use the screen –ls command.
If you have multiple sessions running, you may need to find the screen session ID
To list different Screen sessions from a standard command line with:
This only lists sessions that are created with the screen command. Windows inside a session won’t be listed. If you have multiple different Screen instances running, each will have a different session ID.
This command lists all the Screen sessions that kept running after you disconnected.
You can then reattach to that Screen using the screen –r [sessionID]command.
To reattach to a running Screen instance:
screen –r [sessionID]
Note: If you only have one Screen instance, you don’t need to enter the session ID. If you have more than one, you’ll need to specify which session ID you want to reconnect to.
Like many Linux applications, Screen uses a customizable configuration file. Find the system-wide configuration file at /etc/screenrc. The user’s configuration file is located at ~/.screenrc.
Open the file for editing:
sudo nano /etc/screenrc
Most of the settings can be toggled by removing the comment (#) sign at the beginning of the line.
This tutorial showed you how to install Linux screen as well as the basic commands for using it.
Once you have mastered using the screen interface, you can navigate through multiple terminals, multitask and work more efficiently.