climagic Logo climagic

Screen is a powerful program for the command line that allows you to run multiple terminals similar to the way you would have multiple tabs in a web browser. Plus, you can connect and detach from the session like you would a remote desktop session (like VNC or Windows Remote Desktop).


Starting, detaching and reattaching

To get started login to your account and type this command:


The window will refresh and you'll see a single command prompt. You are now inside of a screen session. Try typing a command like ls inside this session:


Now detach from this screen session by pressing Ctrl-a then d. This means "detach".

Ctrl-a d

Now you are back at the command prompt you had before you started screen int he first step. The screen session is still running, but you are not attached to it so you can't see what is going on there. To reattach to it, try running the screen command again with the -x option.

screen -x

You should now see the screen session including how you left it, displaying the results of the last command you ran (like a directory listing). Note that many screen tutorials start out by using the -r and -d options for detaching and reattaching from a running screen session. I find these more clumsy to use because you have to remember to

Navigating screens

While inside a screen session, you can create additional terminal windows and navigate between them. Create a new terminal window with Ctrl-a c

Ctrl-a c

Screen will create a new window/shell and automatically switch you to it. To go back, you can press Ctrl-a and the backspace key or you can move forward (and it will wrap around) by pressing Ctrl-a and the space key.


Ctrl-a <SPACE>

Try these two now to get a feel for pressing the key sequences. It will eventually become a part of your muscle memory, like typing itself.

You can create many windows if you want, detach from them and come back later and use the keystrokes above to navigate through them. With these few simple commands, you can get started with screen.

Common problems

Multiple sessions running

One thing that people new to screen often will do is start up multiple screen sessions and forget about them. Probably because they just ran screen without the -x option to reattach to the already running session. You can recover from this by running screen -x and either it will reattach to a single session or if you have multiple sessions open, it will list them out like this:

There are several suitable screens on: 25317.pts-39.ludwig (11/02/2009 04:49:52 PM) (Detached) 25214.pts-39.ludwig (11/02/2009 04:49:50 PM) (Detached) 25091.pts-39.ludwig (11/02/2009 04:49:46 PM) (Detached) Type "screen [-d] -r [pid.]" to resume one of them.

Now you need to choose which session you want to reattach to. The number you need to specify is the first number shown on the line. So if I wanted to attach to the second one, I would run:

screen -x 25214

Then I could do whatever I need to in that session.

Dead sessions

Another common problem that usually is the result of a server reboot is when your screen sessions are dead and some files need to be wiped before you can continue. To fix this, you just need to run screen -wipe

screen -wipe

External links