opened image

    The screen utility can be useful on a server running a Linux operating system. From the man page: Screen  is  a  full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells). This utility can be used, for example, if you need to start a process manually and then disconnect from the server. Or it is necessary to save the session if there is a possibility of losing the session, or the possibility that some abnormal disconnection from the server will occur, for example, when the Internet connection fails.

    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:

    yum installscreen

    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:

    screen -ls


    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:


    screen -r

    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:

    man screen

    You can get help on the combinations that can be used inside screen by first pressing Ctrl+a followed by the "?" character.







    The main features of the screen utility, the creation of sessions from which you can disconnect or run long processes without fear of disconnecting from the server, were considered.