Introduction to GNU Screen

What is Screen?

Screen is a full-screen window manager that multiplexes a physical terminal between several processes.

What the heck does that mean? Well it means that you are running a virtual terminal as a process. This allows you to do all sorts of neat things, from disconnecting and resuming the terminal where you left off, to mirroring the screen so students can watch your session, to split terminal screens. Screen is one of those tools that most system admins simply can’t live without.

Installing Screen

For Debian/Ubuntu based systems running Firefox you can install screen by clicking here. Otherwise use your package manager:

sudo apt-get install screen

You might have screen already installed on your distribution. Type, ‘which screen‘ to find out.

What is it good for?

Leaving the Terminal

Probably the most common use for screen is attaching and detaching screen on a remote system. Let me explain. So you are doing some work on a system and you need to upgrade a few apps. A few minutes go by and you realize you have to leave. You need to know when the process finishes or if it even finishes at all. If you were to log into the machine from a different computer you would be able to tell if the task was still running by checking the running processes but you wouldn’t know if it finished OK, or if it needs user input since the SSH terminal is open to the original computer only. Screen can be setup to allow you to detach your session and resume it by connecting to another computer eliminating the problem that was just described which screen.

To do this start up screen with:

screen -S sessionname

Then do your task when you are ready to detach the console do:

Ctrl+a d

Now when you are ready to resume work you can use:

screen -r sessionname

Your session should restore exactly how you left it.

Split Windows

Using screen to have split console screens is another use for screen. This allows for some neat things. Programmers often use this so they can have their text editor open and a shell open below it to execute the program they are working with. This is especially useful for scripting languages like Perl or Python. You could also use a split screen to open a man page of the program you are working on.

Split the screen with:

Ctrl+a S

Create a new window with:

Ctrl+a c

You can resize with:

Ctrl+a :resize

Switch windows wtih:

Ctrl+a tab

Split windows with screen

Kill a window with:

Ctrl+a k

Pair Programming

A less common approach to using screen is utilizing the multiuser mode to do pair programming or create a teaching environment.

Turn multiuser mode on:

Ctrl-a :multiuser on

Add permissions for user (change user to the username you want to allow screen access):

Ctrl-a :acladd user

Now instruct the second user to connect to the screen with:

screen -x user/sessionname

Now the session is shared and both programmers can type into the terminal.

Further reading

Subscribe via Email

Subscribe to Nixtutor via Email

Enter your email address:

Was this information useful?

10 Responses

  1. Ross

    4-13-2009

    It might be useful to know how to kill your extra window in part two. :)

  2. Mark Sanborn

    4-13-2009

    Oh yea good call, thanks Ross I’ll add that to the article.

  3. Greg

    4-13-2009

    I use tmux (tmux.sf.net) nowadays.
    It has almost the features of screen i use, its much more lightweight, with a clear code base, and BSD licensed.

  4. Matthew

    4-13-2009

    I recently discovered INX (http://inx.maincontent.net/). This is an Ubuntu-based live CD that lacks an X server and is set up as a learning tool about the command line. It includes comprehensive coverage of GNU Screen, and is a good tool for newbies to play with – you’re never left at a blank screen, it’s all menu driven, and the coverage on Screen is pretty good.

  5. lefty.crupps

    4-13-2009

    > Your session should restore exactly how
    > you left it.
    Well, sort of; a detached screen doesn’t ‘pause’ any running task, so using Screen is nice to start a process and then detach it, and come back to it later once it’s done running.

  6. mudrii

    4-13-2009

    nice tutorial Thx for sharing nfo

  7. [...] Screen Quick Reference – Quick reference to a must have screen emulator, Also check out Introduction to GNU Screen [...]

  8. Dominik

    4-14-2009

    hi, nice article.

    additionally, you can write, how to copy/past with

    ctrl-a esc # copy mode
    arrow keys # move to text
    space # begin marking
    arrow keys # marking
    space # end marking
    ctrl-a ctrl-a # jump to another screen
    ctrl-a ] # past

  9. [...] Introduction to GNU Screen (tags: screen linux admin) [...]

  10. [...] Introduction to GNU Screen (tags: systems gnu intro introduction screen interesting howto admin linux sysadmin unix server share administration hack remote sharing tool network) Comments (0) [...]