Using Screen or GNU screen you can start a screen session and open any number of virtual terminals inside a session. Processes under that
screen will remains continue to run even if drops the connection.
Install Linux GNU Screen
Currently, most Linux distributions have pre-installed the screen package. To check the whether it is installed or not, type:
Screen version 4.06.02 (GNU) 23-Oct-17
If the screen is not installed on your system, you can installed easily.
Install Screen on Ubuntu and Debian
sudo apt install screen
Install Screen on CentOS and Fedora
sudo yum install screen
Starting Linux Screen
Open your terminal and type
screen to launch the screen:
It will start a new window within the screen. To get the list of all commands type:
Starting Session with Name
When have multiple sessions, it is difficult to find. We can create session by giving name which will be very useful to identify. To create a session with name, run following command:
screen -S session_name
Here, you should replace session_name with your appropriate name.
Linux Screen Windows
When a new session started, it creates a single window with a shell in it. You can have multiple windows inside a 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:
Ctrl-a + cCreate a new windows.
Ctrl-a + wDisplays the list of all currently opened windows .
Ctrl-a + ARename the current window.
Ctrl-a + nGo to the next windows.
Ctrl-a + pGo to the previous windows.
Ctrl-a + Ctrl-aToggle between current and last window.
Ctrl-a + kClose the current windows (kill).
Ctrl-a + SSplit the current windows horizontally.
Ctrl-a + |It split the current windows vertically.
Ctrl-a + dDetach a screen session without stopping it.
Ctrl-a + rReattach a detached screen session.
Ctrl-a + [Start the copy mode.
Ctrl-a + ]Paste the copied text.
Detach from Screen Session
To detach from the screen session at any time type:
The running program in screen session will be continue to run even after you detach from the session.
Reattach to a Screen
You can resume your screen session using the following command:
Add the session id after the -r flag if you have multiple session started. Below is the example:
screen -r 11205
Here, 11205 is the session id. To get the list of session ID for current running screen type:
There are screens on: 11205.pts-0.tecnstuff-desktop (Detached) 11335.pts-0.tecnstuff-desktop (Detached) 11408.pts-0.tecnstuff-desktop (Detached) 3 Sockets in /run/screens/S-tecnstuff.
In this tutorial, you learned how to use GNU Screen in Linux to resume the sessions even after disconnected. Now you can start use of the Screen utility to create multiple screen windows from a single session, detach and resume screen sessions.
To learn more about GNU Screen visit Screen User’s Manual page.
Feel free to leave a comment if you have any questions.
Leave a Reply