By popular request, I’ve been asked to write a quick introduction to screen. Screen is a terminal window manager, that allows you to run multiple shell windows concurrently from a single connection. In summary, you can do this:

Some common scenarios for using screen:

  • Editing source code and running tooling or debuggers next to each other.
  • Keeping a stable working layout environment on a remote box that you can connect/disconnect to at will.
  • Keeping a long-running IRC session.
  • Pair programming on Vim or Emacs over geographically distinct locations using SSH.

For reference – GNU documentation is available here, and the Default Key Bindings are available here.

Install Screen

OS X comes pre-packaged with a version of screen, any sensible version of a Unix based operating system will too. If you’re on Ubuntu, and screen appears to not be installed (this surprised me):

sudo apt-get install screen

Screen does appear to be availible with Cygwin, if you want shell and screen functionality on Windows.

Starting Screen

This is not rocket science. You need to start screen before you can start working in screen.

screen

All good, you should get a copyright message. When you clear the message… nothing looks to have changed, you’re staring at a terminal again. This is fine, and as it should be. You’re now inside a window inside of screen, just the one for now. It can get a bit meta after this.

Concepts

Screen keeps track of a number of windows. Each window is a shell instance in its own right, which may or may not be attached to a region. You many have multiple windows running at any one time, in a multiplex of vertical and horizontal regions. Each window can be switched to any of the regions.

Most commands within screen start with Ctrl-A. This is the default keymapping and can be changed in a configuration file or at the time of starting screen.

Windows

  • Add a Window – Ctrl-a a
  • Kill a Window – Ctrl-a k (If possible, exit terminal normally)
  • Detach Screen – Ctrl-a d (Leave running in background)

  • List all Windows – Ctrl-a “
  • Set Title For Current Window – Ctrl-a A (Useful for keeping track)
  • Switch current Region to Window [n] – Ctrl-a [n]

When a window is detached, it is still running in the background. If you are ssh-ing to a remote box, and running screen on the remote box, your screen window will continue to run if your session becomes disconnected. This can be a gods-send on train journeys.

Screens can be reattached at the terminal, before screen is started.

screen -list

Will give a list of all running screens. Running:

screen -dr [id]

Will then reattach the window with the given id. Running the above without the id will attach the first non-connected screen.

Regions

Regions are the mechanism which allow you to display multiple windows simultaneously. The are achieved by “splitting” the current region and then selecting the window (Ctrl-a [n]) to display. You can switch between the regions on display using Ctrl-a Tab, the man page also discusses mappings for move intuitive movement.

  • Horizontal Region Split – Ctrl-a S
  • Vertical Region Split – Ctrl-a
  • Kill the Current Region – Ctrl-a X

  • Switch Focus To Next Region – Ctrl-a Tab

More

This is just a quick introduction to whet your appetite. There’s more to be had from screen, and the man page is a good place to start, as well as a whole Google of search results. Screen is a remarkably flexible tool. As an example, a friend of mine has discussed the way their company pair programmes using a screen session to view another user’s screen session. All working over ssh using no more fancy tooling than a standard Linux box.