Linux Screen

Apr 2020

Overview

When using Linux via SSH, if you get disconnected then you cannot rejoin that session. So if you were doing something like downloading a large file, then you can not reconnect to see the progress (the download would have stopped anyway once you disconnected).
This guide is based around CentOS7 (or RedHat).
Screen is a 'Terminal Multiplexer' which means you can start Screen and then open terminal windows. These windows will stay open if you disconnect and you can reconnect with them when you next join.

Check for Screen

Sounds great, do I have Screen?
From a terminal in Linux, enter the following:

screen --version

If you see a version number in the format Screen version 4.01.00devel (GNU) 2-May-06, you are good to go, check out the section Using Screen. if you see the message screen: command not found then you will need to install screen.

Installing Screen

To install screen, open a terminal window and use the following command:

sudo yum install screen -y

You will see something very similar to the following:

sudo yum install screen -y
Loaded plugins: fastestmirror
Determining fastest mirrors
epel/x86_64/metalink | 8.3 kB 00:00:00
* base: centos.mirroring.pulsant.co.uk
* epel: ftp.nluug.nl
* extras: mirror.mhd.uk.as44574.net
* updates: mirror.vorboss.net
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/7): base/7/x86_64/group_gz | 153 kB 00:00:00
(2/7): extras/7/x86_64/primary_db | 190 kB 00:00:00
(3/7): updates/7/x86_64/primary_db | 120 kB 00:00:00
(4/7): epel/x86_64/updateinfo | 1.0 MB 00:00:00
(5/7): epel/x86_64/group_gz | 95 kB 00:00:00
(6/7): base/7/x86_64/primary_db | 6.1 MB 00:00:01
(7/7): epel/x86_64/primary_db | 6.8 MB 00:00:02
Resolving Dependencies
--> Running transaction check
---> Package screen.x86_64 0:4.1.0-0.25.20120314git3c2946.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================================================================================
Package Arch Version Repository Size
================================================================================================================================================
Installing:
screen x86_64 4.1.0-0.25.20120314git3c2946.el7 base 552 k
Transaction Summary
================================================================================================================================================
Install 1 Package
Total download size: 552 k
Installed size: 914 k
Downloading packages:
screen-4.1.0-0.25.20120314git3c2946.el7.x86_64.rpm | 552 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : screen-4.1.0-0.25.20120314git3c2946.el7.x86_64 1/1
Verifying : screen-4.1.0-0.25.20120314git3c2946.el7.x86_64 1/1
Installed:
screen.x86_64 0:4.1.0-0.25.20120314git3c2946.el7
Complete!

Using Screen

To start screen, simply use:

screen

You can check what screen commands are available by: Press CTRL+a (let go of all keys) then hit ?

Screen key bindings, page 1 of 1.
Command key: ^A Literal ^A: a
break ^B b flow ^F f lockscreen ^X x pow_break B screen ^C c width W
clear C focus ^I log H pow_detach D select ' windows ^W w
colon : hardcopy h login L prev ^H ^P p ^? silence _ wrap ^R r
copy ^[ [ help ? meta a quit \ split S writebuf >
detach ^D d history { } monitor M readbuf < suspend ^Z z xoff ^S s
digraph ^V info i next ^@ ^N sp n redisplay ^L l time ^T t xon ^Q q
displays * kill K k number N remove X title A
dumptermcap . lastmsg ^M m only Q removebuf = vbell ^G
fit F license , other ^A reset Z version v
^] paste .
" windowlist -b
- select -
0 select 0
1 select 1
2 select 2
3 select 3
4 select 4
5 select 5
6 select 6
7 select 7
8 select 8
9 select 9
I login on
O login off
] paste .
| split -v
:kB: focus prev

Starting a “Named Session”
You can name your screen sessions, which makes it easier to find the one you were in, you can do this using the following syntax:

screen -S session_name

For example screen -S Orca
You will not see a lot happen, but a new window has opened and you are in a new session.
When you start a new screen session, it creates a single window with a shell in it.
You can have multiple windows inside a Screen session.
To create a new window with shell, type Ctrl+a then c, the first available number from the range 0…9 will be assigned to it.
Below are some most common commands for managing Linux Screen Windows:

Ctrl+a c Create a new window (with shell)
Ctrl+a " List all window
Ctrl+a 0 Switch to window 0 (by number )
Ctrl+a A Rename the current window
Ctrl+a S Split current region horizontally into two regions
Ctrl+a | Split current region vertically into two regions
Ctrl+a tab Switch the input focus to the next region
Ctrl+a Ctrl+a Toggle between the current and previous region
Ctrl+a Q Close all regions but the current one
Ctrl+a X Close the current region

Detach from Linux Screen Session
You can detach from the screen session at any time by typing:

Ctrl+a d

The program running in the screen session will continue to run after you detach from the session.