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.
- Press
Ctrl+A[ - Use Arrow Keys, PageUp/PageDown to scroll.
- Press
Escto exit.
Split Screen
Ctrl+AS: Split horizontally.Ctrl+A|: Split vertically.Ctrl+ATab: Switch focus to next region.Ctrl+AX: Close current region.Ctrl+AQ: Close all other regions.
Logging
To log everything you see to a file.
- Press
Ctrl+AH - Creates
screenlog.0in current dir. - Press again to stop.
Session Sharing (Pair Programming)
- Host starts screen:
screen -S pair - Host enables multi-user:
Ctrl+A:multiuser on - Host allows user Bob:
Ctrl+A:acladd bob - Bob SSHs into the same server.
- Bob connects:
screen -x hostuser/pair
Now both see and type in the same terminal!
Notes
- tmux:
tmuxis the modern alternative toscreen. It is generally more user-friendly and scriptable. - Config:
~/.screenrchandles configuration.