User Tools

Site Tools



Screen is the best sysadmin and cluster user companion. It does a magical thing: if you disconnect abruptly from a server, it will keep everything running as is you've never disconnected. Think of it as an open window to your work on a remote machine, to which only you can have access.

To give an idea of what screen does, follow this simple tutorial in which we will be using the top utility that shows processes running on a machine. The tutorial shows how, if you start top in a screen session and you disconnect from a server, the top program is still running on the remote machine.

Please read tips at the end on how to use copy mode and move in the open window.

1) login via ssh into a server and run screen:
[pflorido@n12 pp]$ screen

An intro page will appear where you have to press enter or space. At this point you are in a virtual shell running on the server, independent from the ssh connection. If connection drops by during this time you don't loose your session.

2) start the top command
[pflorido@n12 pp]$ top

A lot of info about running processes will fill the terminal.

3) press the three keys ''Ctrl a d'' alltogether

The screen session will be detached. you'll see a message like:


and you will be sent back to the shell where you wrote screen before.

4) list the existing screen sessions

With the command

[pflorido@n12 pp]$ screen -list

You'll see a list of running detached or attached screens, like this:

There is a screen on:
	20440.pts-1.n12	(Detached)
1 Socket in /var/run/screen/S-pflorido.
5) re-attach the open screen by copy pasting its name:
[pflorido@n12 pp]$ screen -DR 20440.pts-1.n12
6) gaze at top command still running!

You should now see the running processes as if top command was never stopped. In fact it had never stopped!

Press q to exit it and keep working on the same screen shell.

7) >:-| I don't believe it works!

You can try screen effectiveness this way:

  1. log into the cluster
  2. running screen
  3. close the terminal window wgere you ran it
  4. relogin via ssh and run screen -list: the screen session is still there!!

The Copy Mode and other stuff

Inside a screen session, interaction with the shell changes. In particular, to scroll up and down you should use the combination:

  • Ctrl a ESC to enter copy mode. Then you can move the cursor up and down in the screen session.
  • Ctrl a ? will give you a list of commands
  • man screen will give you more info.
  • On the same ssh connection you can open multiple screen terminals so that you can have multiple windows open, with Ctrl a c
    • you can move between existing screen terminals with
      • Ctrl a p previous
      • Ctrl a n next
  • You can name each session so that you remember what that was about with the -S flag:
    [pflorido@n12 pp]$screen -S " Don't screen at me!"
    [pflorido@n12 pp]$ screen -list
    There are screens on:
    	20550.Don't screen at me!	(Detached)
    	20440.pts-1.n12	(Detached)
    2 Sockets in /var/run/screen/S-pflorido.
it_tips/screen.txt · Last modified: 2014/03/27 11:08 by florido