I know most of you have already heard about screen, but for those who haven’t, it is one of the best thing you could know and work with, being in this field. Everyone of you must have run through the scenarios where you are running a time consuming task on a remote server and your internet connection drops in between, you might have to run something and check the logs on the console later on, you want to give a small training to a remote person but can’t show them how to do things. These are just few problems where screen will come to the rescue.

Screen is a utility provided by GNU and usually comes pre-installed in most of the distros. If not, then using the package manager for your respective distros, you can install screen.

Like for Fedora/centos/redhat:

$ sudo yum install screen -y

For ubuntu based systems:

$ sudo apt-get install screen -y


Info: The key bindings given in this tutorial are all case sensitive, so Ctrl+c is not equal to Ctrl+C

Creating screen sessions:

First time you need a start a screen session, which can be done easily by using the command screen.

$ screen

If you want to give your screen session a name, so that you could identify it later, then you need to create a session like this:

$ screen -S napster

Once you have created one instance of screen, you can have multiple sessions inside that screen instance, or you can say in other words, multiple tabs.

To create more session, use “Ctlr+a” followed by “c“.

To check what screen session you are running, use this command:

$ screen -ls

There is a screen on:
8762.napster (Detached)
1 Socket in /var/run/screen/S-napster.

Detaching and Attaching:

To detach from an attached screen, use “Ctrl+a” followed by “d“.

Now, from the next time you just need to come and re-attach to your previous screen session like this

$ screen -d -r napster
  -d = detach from any previous session
  -r = reattach to this session

If there are more than one screen session running, and you haven’t given them names, then use the pid of the screen session to attach to that specific screen.

$ screen -r pid

If you want to attach to a screen, which is already attached to someone else’s window, and you don’t want others to be disconnected, use “-x” instead of “-r

$ screen -x screen_name/pid

By default all the sessions will be with named “bash”, though you can rename them according to your comfort, with “Ctrl+a” followed by “A“.

When you have more than one session, you can switch between them using these shortcuts:

Ctrl+a” followed by “n”  –> next session

Ctrl+a” followed by “p”  –> previous session

This was mostly the basic working of the screen which should be pretty good for most of the people. But there are lots of advanced features which lots of people have never used or heard of. Will write and post the next blog with those features. Stay Tuned.

If you enjoyed this post, make sure you subscribe to my RSS feed!!!!