To work with the screen utility, you will need to connect to the server via ssh. (Our blog has a separate article about this)
To install the screen utility run in deb-like distributions:
apt-get install screen
In rpm-like ones:
To run the utility, enter the following at the command line:
You can also start a session with a name, for example:
screen -S archiving
After entering these commands, a screen session is created, which looks like a regular terminal. You can work in it like in a regular terminal, enter commands, including launching long processes, which, presumably, can be interrupted in work.
The screen session can be disconnected and you can disconnect from the server, continue to perform other tasks, or start another screen. To detach from screen, type Ctrl+a, d on the keyboard (first press Ctrl+a together, then d). You will return to the previous mode of your ssh session, from which you can disconnect.
Multiple screen sessions can be opened. If you do not specify a name when creating a session, it will be assigned a numeric identifier and a default name. To view a list of screen sessions, run the command:
In the output, you can see a list of sessions: their identification number and name. If no name has been given, it is added automatically (for example, pts-0.myserver).
To rejoin an existing session (if there was one), run the command:
If there are multiple sessions, a list of existing ones will be displayed. To join a specific session, you must specify its name. For example,
screen -r archiving
screen -r 30887
To exit the screen session and close it, type exit or press Ctrl+d.
Not all possibilities of this utility are considered. There are many other command line options, as well as commands that can be used inside a screen session (such as creating windows, switching between them, and many others). In order to learn all the features of the program, refer to its reference manual:
You can get help on the combinations that can be used inside screen by first pressing Ctrl+a followed by the "?" character.