Back to main page

The Quick-N-Dirty Guide to screen

Screen is a useful application. We're only going to cover some of its more common uses in this article.

1.) Do you have screen

At a command prompt type
which screen

If you get an answer like /usr/bin/screen or /usr/local/bin/screen go to step three, otherwise go to step two.

2.) Installing screen

See our installation guide for instructions on installing screen in your distribution. It's a well-known application so almost all distributions have their own version of it.

3.) Using screen

Screen has several uses. Its most basic use more or less duplicates virtual consoles (that is, it's similar to tabbing between consoles with alt+F1, F2, etc.

First, start the screen program by typing

screen

There will be a little note about it, with instructions to hit the space bar or return to continue.

So, let's say that I want to check email with mutt in console and also wish to untar something that I downloaded. First, I type mutt to open my email. Now, I want to untar the download.

By default the prefix to screen commands is Ctrl+a, hereafter abbreviated C-a. So, I start with that.

C-a
c

The second c will bring me to a command prompt. I can move back and forth between the two screens with C-a n (for next) and C-a p (for previous).

The usefulness of this is more apparent with a remote login. Now you can do several things with one remote terminal.

My most frequent use of it is when I'm working on something either in X, console or remotely, and may want to change from one to another.

For example, while at home, I log into a server at work. I have something that might take time on the server, but my connection between home and work is problematic. So, I get on through our company's VPN and log into the server.

Now, I have to copy a very large directory which may take 20 minutes. If my connection gets cut off during that twenty minutes, something may go wrong. However, if I use screen

screen cp SP02 SP02.bak

I can now detach the screen.

C-a
d

This will detach the screen. I can now log off. Ten minutes later, I wish to check on its progress so once again I connect and

screen -r

The d and r stand for detach and reattach. If the process is finished, I will get a message that there is no screen to be resumed. Otherwise, it will put me back where I was when I detached the screen.

Another handy use of screen is to make two windows in a console. To do this

C-a
Shift+S

This creates a second window. The cursor is still in the top window

C-a
tab
C-a
c

One tabs to the second window, then does the C-a combination again and c. You will then be able to enter a command. This is far less cumbersome to do than it may seem from reading it.

If you wish to go back to one window, I've found the easiest thing to do is exit (by, oddly enough, typing exit) from one window. Then, detach the screen with C-a d. Now, reattach it with screen -r and you should be back to only one window.

References
man screen

Back to main page