1 Introduction
screen can retain the session very conveniently, avoiding the termination of the running command due to the timeout of the SSH terminal connection time, or disconnection due to network factors and other reasons.
screen can also easily run foreground interactive programs in the background (such as: Minecraft server, make compilation)
There are three main functions of screen:
- Session recovery: As long as the Screen itself is not terminated, the session running inside it can be resumed.
- Multi-window: In the Screen environment, all sessions run independently and have their own number, input, output and window cache.
- Session sharing: Screen allows one or more users to log in to a session multiple times from different terminals, and share all the features of the session (for example, you can see exactly the same output).
These three functions are actually intertwined to form a command set with various screen functions.
2. Installation
CentOS:
1 | yum install screen |
Debian/Ubuntu:
1 | apt install screen |
3. Use
3.1, help query
The help documentation of screen is so detailed that it may take a few minutes to check a command; but you can directly use the help command to query the command you need:
1 | screen-help |
Through this command, you can query most of the commonly used commands.
3.2, terminal list
implement:
1 | screen -ls |
You can view the terminal that has been created (running in the background):
3.3, Create a new terminal
general direct execution
1 | screen |
A new terminal will be entered, press Ctrl +A and Ctrl+D to return to the terminal.
The official method recommended by screen to create a virtual terminal is:
1 | screen -S ExampleTerminal |
Another way is:
1 | screen -R ExampleTerminal |
Comparison of three creation methods:
- Use -R to create, if there is only one screen with the same name created before, then directly enter the previously created screen
- The virtual terminal created by using -S and directly entering screen will not check the screen created before (that is, a screen with the same name will be created)
3.4, back to the terminal
implement:
1 | # Use the screen -r command screen -r [pid/name] |
Where pid/name is the process ID of the virtual terminal or the terminal name specified when creating it.
3.5, clear the terminal
Enter the terminal according to the above method and execute:
1 | exit |
Or execute directly in the main terminal:
1 | screen -R [pid/Name] -X quit |
Install Screen on Linux
Comments