Log in

No account? Create an account

Aaron Brown

Share Next Entry
08:43am: GNU Screen cheat-sheet

I created this account so I could see some people's friends-only posts, but I might as well post something of my own.

If you use console-mode unix programs and would like to

  • leave stuff running when you log out of a machine and have it still be running when you log back in,
  • or switch between multiple programs without using Ctrl-Z/fg or multiple terminal windows,
  • or be able to see multiple programs at once without using multiple terminal windows,
  • or copy and paste between programs without using the mouse,

then you will like GNU Screen. At my old job I sat at a Windows 2000 machine but did most of my work on a GNU/Linux machine (in a closet). Every day I logged into my desktop machine, logged into the closet machine via PuTTY, and ran screen -D -R, which brought up all of the Linux stuff I had left running the day before. Here's a cheat sheet I came up with to learn screen's keystrokes:

GNU screen usage

  This is a summary of some common command-line options and
  keystrokes for use in the terminal multiplexer GNU screen.
  For more details, see screen's man page.  All commands
  (except in copy/scrollback mode or command-line mode)
  start with the command character, which is assumed here to
  be the default Ctrl+A (notated here as "C-a").

Command-line options

  screen    When called from inside a screen session (on the
            computer that that screen session is running
            on):  Open up a new window with a command shell
            in it.  When called from outside a screen
            session:  Start a new screen session.

  screen -D -R
            Reattach a detached screen session.

  screen -t Fooing foo bar baz
            Create a new window, run the command "foo" with
            arguments "bar" and "baz" in it, and title it

  screen -e^Oo
            Start a new screen session with a command
            character of "C-o" (and a literal Ctrl+O
            sendable as "C-o" followed by "o").  This is
            useful when you have a screen session running on
            computer foo, inside which you are sshed into
            computer bar, and you want to start a screen
            session on computer bar with a different command

Basic command-character commands

  C-a ?     Help.

  C-a a     Send the command character itself ("C-a") to the
            program running in the current window.

  C-a "     Present a list of all windows for selection.
            Use the arrow or number keys (or vi- or
            Emacs-style cursor keys) to highlight a window
            and press <Enter> to switch to it.

  C-a 0     Switch to window number 0 (works with 0-9).

  C-a C-a   Toggle to the window displayed previously.  (If
            you're using another command character,
            substitute it for both these "C-a"s.)

  C-a A     Change the current window's title.

  C-a c     Create a new window with a shell and switch to
            that window.

  C-a <Esc> Enter copy/scrollback mode.  (See
            "Copy/scrollback mode" section below.)

  C-a ]     Send the contents of the paste buffer to the
            program running in the current window.  (See
            "Copy/scrollback mode" section below.)

  C-a t     Show time, date, hostname, and some other stuff.

  C-a @     Do nothing.  (Useful when you hit "C-a" by

  C-a :     Enter command line mode.  Examples:
            - "C-a :number 7" changes the window number of
              the current window to 7.
            - "C-a :escape ^Oo" sets the command character
              to Ctrl+O.
            - "C-a :hardstatus alwayslastline" makes status
              show up on the last line rather than the
              terminal title bar.
            See the man page for more details.

  C-a C-z   Suspend screen.  (You will be back at the shell
            you started screen from.)

  C-a d     Detach screen.  (Do this before you log out --
            you will be back at the shell you started screen

Copy/scrollback mode

  h,j,k,l   Move cursor left, down, up, right (as in vi).
            Regular arrow keys also work.

  C-b       Page up (<PageUp> key also works).

  C-f       Page down (<PageDown> key also works).

  <Space>   Set mark.  When the second mark is set, the text
            between the two marks will be put into screen's
            paste buffer and copy/scrollback mode will be

  ^         Move to first nonwhitespace character on current

  $         Move to last nonwhitespace character on current

  0         Move to leftmost column.

  c         Set the left margin for block-mode copying.

  C         Set the right margin for block-mode copying.

  x         Exchange the first mark with the current cursor
            position.  This is good for moving an already
            set mark.

  <Esc>     Exit copy/scrollback mode.  (Any key that
            doesn't have another meaning will do this.)


  Regions allow looking at two or more screen windows at the
  same time.

  C-a S     Split the current region into two new ones.
            (The blank window will be displayed in the new
            region until you use one of the window selection

  C-a <Tab> Switch focus to the next region.

  C-a Q     Delete all regions but the current one.  (This
            does not destroy any windows.)



Date:2006-Mar-02 06:15pm (UTC)
I was going to say the same thing.
(Replies frozen) (Thread)
[User Picture]
Date:2006-Mar-09 10:56pm (UTC)
(Replies frozen) (Thread)
[User Picture]
Date:2006-Mar-10 04:19pm (UTC)



Will I see you on Saturday with Mary? Have we figured out the details on that yet? If we get together after her hair appointment, that would work out to about 3pm.


(Replies frozen) (Parent) (Thread)
Date:2006-Mar-10 11:55pm (UTC)
How about PF Chang's? I love their lettuce wraps, they're yummy.

Four would probably be safer just to account for lateness at the salon and drive time. Does that work for you?
(Replies frozen) (Parent) (Thread)
[User Picture]
Date:2006-Mar-11 03:43am (UTC)

How about PF Chang's? I love their lettuce wraps, they're yummy.

Four would probably be safer just to account for lateness at the salon and drive time. Does that work for you?

Yes. I'll let Bill know too.

(Replies frozen) (Parent) (Thread)
Date:2006-Jul-14 01:05am (UTC)

pf changs

the only thing they have edible is the lettus wraps
(Replies frozen) (Parent) (Thread)
Date:2010-May-10 10:54pm (UTC)

Re: pf changs

Agreed - chang's is always a disappointment :(
(Replies frozen) (Parent) (Thread)
Date:2007-Aug-27 11:34am (UTC)

Thank You for site

Thank you for your site. I have found here much useful information.
Good site ! ;)
(Replies frozen) (Thread)
Date:2008-Mar-14 03:12am (UTC)

The same cheat sheet in PDF

Hi! I made a PDF version of the same cheat sheet.

I posted it to my blog, catonmat -- good coders code, great reuse:
Screen Terminal Emulator Cheat Sheet (http://www.catonmat.net/blog/screen-terminal-emulator-cheat-sheet/)

PS. I also have several other cheat sheets on awk, ed, sed, perl and bash. Navigate to Projects -> Programming Cheat Sheets to find them!

Peteris Krumins
(Replies frozen) (Thread)
Date:2011-Feb-03 02:08am (UTC)

Re: The same cheat sheet in PDF

thank you :-)
(Replies frozen) (Parent) (Thread)
Date:2011-Feb-15 01:52am (UTC)
Thought I would comment and say neat theme, did you make it for yourself? It’s really awesome!
(Replies frozen) (Thread)
[User Picture]
Date:2011-Feb-15 04:36am (UTC)
I just picked it out of a list on some LJ configuration screen. (Long long ago. I may have mixed and matched some colors or something.)
(Replies frozen) (Parent) (Thread)
Powered by LiveJournal.com