screen command serves a couple of very useful purposes. The first is to maintain a session even if you get disconnected. This is especially useful if you are working remotely for a prolonged period of time. The second purpose is to allow you to have multiple sessions open at the same time to the same server without opening a fresh connection for each one.
screen is an ongoing project and due to this different Linux distributions have different feature sets. This tutorial has been tested on Centos 6.6 and Ubuntu 14.04. Where a feature we are covering doesn’t exist in one but does in the other, this will be pointed out. Please note however that this may change after the date of publication. To check if the feature is available in your version of
screen please see the man pages:
To open a
screen session type
screen at the prompt. This will open a fresh
screen session where you can begin working.
screen will exist when you close the last shell you are using within screen. On Ubuntu you will now get a welcome screen which you can dismiss by hitting either space or enter. To permanently disable this welcome screen please edit your ~/.screenrc file and add this line.
All commands in
screen start with
Opening a new session/shell and changing sessions.
To open a new shell from within
screen use the
Using only these two options you can have multiple commands running and still have a shell to type new commands into. For instance once you open
screen run the
top then use
Splitting the Screen
To split the screen use the
Once the screen is split you will need to create a new session or attach an existing one. To create a new session use the
To move to the next region use
Listing sessions and assigning a name
You can have multiple
screen sessions, to list all sessions you would use the command
If you have only run
screen once then only one will be listed and it will be called something like this.
This is the
You can however change this using
Reconnecting to a lost Session
If you are running screen and you for instance lose your internet connection. When you come back you can reconnect to that session.
root@ubuntu:~# screen -list There is a screen on: 6956.pts-0.ubuntu (09/17/2015 03:47:19 PM) (Detached) 1 Socket in /var/run/screen/S-root.
You cannot access any shells running in the Detached screen. To re-attach a screen you would use the
-x option like this:
screen -x 6956.pts-0.ubuntu.
If you had split screens running when you lost your connection you will need to rebuild them. To do this create the splits again using
These are the most useful of the
screen features but it does have more features. To find out more please see the man pages for
screen as follows: