6.3.9 Running applications in the background using SCREEN

In this article we will look at the main features of the Screen utility.

Many administrators actively use the screen when using SSH. It is also good for anyone who actively uses the terminal for everyday tasks. Screen allows you to manage multiple sessions from a single console or terminal window. The utility is indispensable when you need to connect to one session from two places at the same time or interact with several sessions. Many administrators love Screen because if the SSH connection is lost, they can return to their session, and the operations in progress at the time of the break will not be interrupted.

Installation, launch and display of help Screen

In a number of Linux distributions (as well as MacOS), Screen is present by default. In the case of Ubuntu/Debian it must be installed separately. You can do this by running the command:

  1. apt-get install screen

Immediately after installation, Screen is ready for use.

To get started, let’s launch Screen without parameters, creating a new screen:

  1. screen

Immediately after launch, a window will appear with information about the creators and the license and will wait for you to press the spacebar or Enter.

Screen commands are executed using the Ctrl-a hotkey. After pressing Screen once, it waits for a command.

Let’s ask Screen for a list of all commands:

Crtl+a -> ?

If it doesn’t work, try again. Press Ctrl+a, release, enter ?.

Examples of practical application of Screen

Let’s get out of the help and practice using it.

To begin with, in the current screen (it is zero in the list), let’s run:

  1. ping

Now let’s introduce

Ctrl+a -> c

With this team we created a new screen and now they work simultaneously.

Let’s run it:

  1. ping

To switch between screens, you can either specify the screen number or select a screen from the list:

  • Ctrl+a ->0 will take us to screen 0.
  • Ctrl+a ->“ will bring up a menu for selecting a screenshot.
  • Ctrl+a ->n will switch to the next screen.
  • Ctrl+a ->p will switch to the previous screen.

Now let’s minimize Screen with our pings. To do this we will use a hotkey

Ctrl+a ->d

After executing the command, Screen will be minimized and we will be taken to our terminal. In order to return, run the utility with the -r switch:

screen -r

Sometimes trouble happens with lost screenshots; in order to connect to them, you need to run the command:

screen -x

then find the number of the lost screen in the output and return it with the command:

screen -x n

where n is the same number.

You can return to the session even after the SSH connection is closed when using Screen remotely, which makes it indispensable when performing many jobs.

You can quickly create a new screenshot of a running program, such as wget, of a large file.

  1. screen wget http://mirror.thehost.ua/debian-cd/7.8.0/amd64/iso-dvd/debian-update-7.8.0-amd64-DVD-1.iso

Using the -S switch when starting Screen, you can specify the name of the screen.

  1. screen -S download wget http://mirror.thehost.ua/debian-cd/7.8.0/amd64/iso-dvd/debian-update-7.8.0-amd64-DVD-1.iso

There is always the option to rename the screen with a hotkey:

Ctrl+a ->A

You can view all active screens with the command:

  1. screen-list

If you need to connect to a screen running in another terminal, you can do this using the command:

  1. screen -x download

Screenshots can be hidden from strangers using a hotkey:

Ctrl+a ->x

Another useful feature of the utility is dividing the window by region.

This is done with a hotkey:

Ctrl+a ->S

You can switch between regions using the hotkey:

Ctrl+a ->Tab

If after switching to a new region nothing can be done, then there is no screen in this region; you can either add it or select it from the existing ones.

Regions are closed with hotkeys:

Ctrl+a ->Q Close all regions except the current one Ctrl+a ->X Close current region

How to remove the welcome window in the Screen utility

After you start actively using Screen, you quickly get bored with the welcome window. You can remove it by adding the following line to the ~/.screenrc file:

  1. startup_message off

You can do this quickly by running the command:

  1. echo startup_message off >> ~/.screenrc

The article covers only the basic capabilities of Screen, so as not to overload with rarely used functionality.