Skip to content

screen Command Cheat Sheet

screen is a full-screen window manager that multiplexes a physical terminal between several processes. Killer Feature: You can start a process, disconnect (detach), go home, SSH back in, and resume (attach) exactly where you left off.


Synopsis

screen [options] [cmd [args]]

Basic Session Management

Start a New Session

screen

Start Named Session

Giving it a name makes it easier to find later.

screen -S deploy_job

Detach (Leave it running)

Press Ctrl+A, then D. Output: [detached from 1234.deploy_job]

List Running Sessions

screen -ls

Reattach (Resume)

screen -r
# OR info specific session
screen -r deploy_job

Reattach if Attached Elsewhere (-d -r)

If you left it open at work, and want to open it at home:

# Detach first, then Reattach
screen -dr deploy_job

Key Bindings

All commands start with Ctrl+A.

Key Sequence Action
Ctrl+A c Create new window
Ctrl+A n Next window
Ctrl+A p Previous window
Ctrl+A " List all windows (select with arrows)
Ctrl+A A Rename current window
Ctrl+A d Detach session
Ctrl+A k Kill current window
Ctrl+A \ Kill all windows (Quit screen)
Ctrl+A [ Enter Copy/Scrollback mode

Copy Mode (Scrollback)

screen doesn't use the regular terminal scrollbar. You must enter copy mode.

  1. Press Ctrl+A [
  2. Use Arrow Keys, PageUp/PageDown to scroll.
  3. Press Esc to exit.

Split Screen

  • Ctrl+A S : Split horizontally.
  • Ctrl+A | : Split vertically.
  • Ctrl+A Tab: Switch focus to next region.
  • Ctrl+A X : Close current region.
  • Ctrl+A Q : Close all other regions.

Logging

To log everything you see to a file.

  1. Press Ctrl+A H
  2. Creates screenlog.0 in current dir.
  3. Press again to stop.

Session Sharing (Pair Programming)

  1. Host starts screen: screen -S pair
  2. Host enables multi-user: Ctrl+A :multiuser on
  3. Host allows user Bob: Ctrl+A :acladd bob
  4. Bob SSHs into the same server.
  5. Bob connects: screen -x hostuser/pair

Now both see and type in the same terminal!


Notes

  • tmux: tmux is the modern alternative to screen. It is generally more user-friendly and scriptable.
  • Config: ~/.screenrc handles configuration.