EN
Linux screen - most useful commands with practical examples
3 points
In this article we are gonna have a look at most useful linux screen commands. Most of the time we just need a few screen commands to get the job done. Below we have a lot of them.
If we run some program from command line and our terminal will shutdown (internet problem, lack of energy) we can't go back to that session. Especially if we run some important installation or download some large file via ssh from another server. It is important to have backup and run this with screen or nohup.
- If we have debian or ubuntu:
xxxxxxxxxx
1
apt-get install screen
- If we have centos:
xxxxxxxxxx
1
yum -y install screen
- screen create new session
xxxxxxxxxx
1
screen -S my_first_screen_session
- screen detach press keys (in this order - first ctrl, second a, third d)
xxxxxxxxxx
1
ctrl + a + d
- screen list all sessions
xxxxxxxxxx
1
screen -ls
Usage example:
xxxxxxxxxx
1
root@mail:/# screen -ls
2
There is a screen on:
3
21173.my_first_screen_session (03/27/2020 09:54:27 PM) (Detached)
4
1 Socket in /run/screen/S-root.
- screen connect to detached session (21173 - id of screen session - NOT ENTIRE NAME, just ID), we can get id by using screen -ls
xxxxxxxxxx
1
screen -r 21173
- screen kill session (21173 - id of screen session - NOT ENTIRE NAME, just ID)
xxxxxxxxxx
1
screen -X -S 21173 quit
Usage example:
xxxxxxxxxx
1
[detached from 21173.my_first_screen_session]
2
root@mail:/# screen -ls
3
There is a screen on:
4
21173.my_first_screen_session (03/27/2020 09:54:27 PM) (Detached)
5
1 Socket in /run/screen/S-root.
6
root@mail:/# screen -X -S 21173 quit
7
root@mail:/# screen -ls
8
No Sockets found in /run/screen/S-root.