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.
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:
- 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:
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
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:
- ping 184.108.40.206
Now let’s introduce
Ctrl+a -> c
With this team we created a new screen and now they work simultaneously.
Let’s run it:
- ping 220.127.116.11
To switch between screens, you can either specify the screen number or select a screen from the list:
Ctrl+a ->0will take us to screen 0.
Ctrl+a ->“will bring up a menu for selecting a screenshot.
Ctrl+a ->nwill switch to the next screen.
Ctrl+a ->pwill switch to the previous screen.
Now let’s minimize Screen with our pings. To do this we will use a hotkey
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:
Sometimes trouble happens with lost screenshots; in order to connect to them, you need to run the command:
then find the number of the lost screen in the output and return it with the command:
screen -x n
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.
- 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.
- 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:
You can view all active screens with the command:
If you need to connect to a screen running in another terminal, you can do this using the command:
- screen -x download
Screenshots can be hidden from strangers using a hotkey:
Another useful feature of the utility is dividing the window by region.
This is done with a hotkey:
You can switch between regions using the hotkey:
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
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
- startup_message off
You can do this quickly by running the command:
- echo startup_message off >> ~/.screenrc
The article covers only the basic capabilities of Screen, so as not to overload with rarely used functionality.