Install Screen on Linux

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:

Bash
1
yum install screen

Debian/Ubuntu:

Bash
1
apt install screen

3. Use

Tip:
Commands are case sensitive!

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:

Bash
1
screen-help

Through this command, you can query most of the commonly used commands.

3.2, terminal list

implement:

Bash
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

Bash
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:

Bash
1
screen -S ExampleTerminal

Another way is:

Bash
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:

Text
1
2
# 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:

Bash
1
exit

Or execute directly in the main terminal:

Text
1
screen -R [pid/Name] -X quit
Author
Hsukqi Lee
Posted on

2022-12-08

Edited on

2022-12-08

Licensed under

CC BY-NC-ND 4.0

Comments

Name
Mail
Site
None yet