December 10, 2010

GNU Screen basics quick reference

Posted in Strategy at 07:06 by graham

Screen is a terminal multiplexer. In simple language, screen allows you to ssh into a machine and open several sessions at once, and leave them running. If you work on remote machines, you need screen.

Install it

sudo apt-get install screen

Configure it

The .screenrc file in your home directory configures screen. Use this to get you started:

# Use bash
shell /bin/bash

# Big scrollback
defscrollback 1024

# No annoying startup message
startup_message off

# Display the status line
hardstatus on
hardstatus alwayslastline
hardstatus string "%{.kW}%-w%{.bW}%t [%n]%{-}%+w %=%{..G} %H %{..Y} %Y/%m/%d %c"

# Setup screens
screen -t 'one' 0 bash
screen -t 'two' 1 bash
screen -t 'extra' 2 bash

# Switch to the first screen
select 0

Start or re-attach: screen -DR. Think of it as the screen doctor. This is the first thing I type after I ssh into a remote machine. If screen is already running, it attaches to it, otherwise it starts a new session.

Essential Commands

All screen commands start with Ctrl-a.

  • Move between terminals: Ctrl-a <num>, so to go to window 1, hold down Ctrl and press a. Release Ctrl, and press number 1.
  • Detach: Ctrl-a d. This is what I type at the end of the day. That leaves everything as it is, and I can re-attach to the sessions next time I ssh in.
  • Exit:Ctrl-a \. Closes all your terminals and exits screen. I very rarely use this.
  • Help: Ctrl-a ?. The help is pretty opaque. Hence this blog post :-)
  • Create: Ctrl-a c. Creates a new terminal. When you’re done using it, simply exit like you normally would. If you find yourself often creating more terminals, edit your .screenrc to start with more.


  • Go to scrollback mode: Ctrl-a <esc>. This is actually Copy mode, but works well for seeing what’s scrolled off the screen
  • Page back: <pageUp>, <pageDown>, <arrow Up> or <arrow Down>. This moves you through the scrollback buffer.
  • Exit scrollback: <esc>. Simply hitting Esc takes you back to your prompt, in normal mode.


Screen allows you to split your window, so you could for example watch the tail of a log file in one half, and work in the other.

  • Split: Ctrl-a S. That’s a capital s.
  • Move between split windows: Ctrl-a <tab>
  • Unsplit: Ctrl-a Q.

I’ve been using screen for many years, and that’s the only commands I use even semi-regularly.

Happy screening!

1 Comment »

  1. Adam Gaskins said,

    September 15, 2018 at 23:29

    This is great! I really appreciate that you posted this. Thank you!

Leave a Comment

Note: Your comment will only appear on the site once I approve it manually. This can take a day or two. Thanks for taking the time to comment.