Linux screen command is one of the most useful command whenever you perform a long-running task like zipping a huge directory or exporting a database from Linux terminal without getting interrupted by sudden connection drop or the SSH session termination. Well, this happened to everyone of us at some point. This is where the screen command comes in that allows us to resume the sessions and save us while working on big process.
In this guide you are going to learn how to use the Linux screen command and perform your tasks.
The screen in Linux is a software package which allows you to open multiple terminal sessions inside your single SSH window. The processes that are running in the screen will continue to run even if you got disconnected from SSH.
Install Linux Screen
The screen package is pre-installed by default on most Linux systems. You can verify it using the following command.
Output Screen version 4.08.00 (GNU) 05-Feb-20
If you don’t have screen installed, you can easily install it using the package manager of your Linux OS.
Install Linux Screen on Ubuntu and Debian
sudo apt update sudo apt install screen
Install Linux Screen on CentOS and Fedora
sudo yum install screen
Starting Linux Screen
You can easily start screen by just typing the screen command.
This will open a new screen session.
Start Named Screen Session
You can also name your screen session with the
screen -S screen_name
This command will create a screen with the assigned name.
Detach from Linux Screen
You can detach from the screen session at any time by typing
You will see an output similar to the one below with your screen name.
Output [detached from 150473.cloudbooklet]
The program that is running in the screen session will continue to run after you get detached from the session.
ReAttach to the Linux Screen
You can re-attach to your screen to see the progress of your work.
If you have multiple screens, you need to use the specific ID to attach.
To get the screen ID you need to list all screens and find the ID.
List all Screens
To list all screens you can use the
Output There is a screen on: 150473.cloudbooklet (03/17/22 09:41:32) (Detached) 1 Socket in /run/screen/S-username.
Here you will see your screen ID and screen name, you can use anyone of this to attach.
screen -r cloudbookklet OR screen -r 150473
Now you will get attached to your specific screen.
Delete Linux Screen Session
To delete your screen session you can just type
exit from your session.
If you need to delete the complete screen session you can use the following command.
screen -X -S screen_id quit
If you have any dead sessions you can use the below command.
Prepare yourself for a role working as an Information Technology Professional with Linux operating system
Manage Linux Screen
Whenever you start a new screen session, it creates a single window with a shell in it.
You can have multiple windows inside a single Screen session.
To create a new window with shell type
c, the first available number from the range
0...9 will be assigned to it.
Below are some most common commands for managing Linux Screen Windows:
cCreate a new window (with shell).
"List all windows.
0Switch to window 0 (by number).
ARename the current window.
SSplit current region horizontally into two regions.
|Split current region vertically into two regions.
tabSwitch the input focus to the next region.
Ctrl+aToggle between the current and previous windows
QClose all regions but the current one.
XClose the current region.
Now you have learned how to use Linux screen in your system.
Thanks for your time. If you face any problem or any feedback, please leave a comment below.