Skip to main content

screen Cheatsheet

By Dejan Panovski Updated on Download PDF

Quick reference for GNU Screen sessions, windows, detach/attach, and common key bindings

GNU Screen is a terminal multiplexer that lets you keep shell sessions running in the background, reconnect later, and manage multiple windows in one terminal. This cheatsheet covers the most useful commands and key bindings.

Start and Exit

CommandDescription
screenStart a new screen session
screen -S workStart session named work
screen -lsList running sessions
screen -X -S work quitStop session work
exitExit current shell/window

Attach and Detach

CommandDescription
screen -rReattach to the only detached session
screen -r workReattach to named session
screen -x workAttach to an already-attached session
screen -d -r workDetach elsewhere and reattach here
Ctrl+a dDetach current session

Prefix and Help

Default prefix is Ctrl+a.

KeyDescription
Ctrl+aEnter screen command mode
Ctrl+a ?Show key bindings help
Ctrl+a :Open command prompt
Ctrl+a "Show window list

Windows

Key / CommandDescription
Ctrl+a cCreate a new window
Ctrl+a nNext window
Ctrl+a pPrevious window
Ctrl+a Ctrl+aSwitch to last window
Ctrl+a 0-9Switch to window by number
Ctrl+a ARename current window
Ctrl+a kKill current window
KeyDescription
Ctrl+a wList windows in status line
Ctrl+a 'Prompt for window number
Ctrl+a SSplit display horizontally
Ctrl+a |Split display vertically
Ctrl+a TabMove between split regions
Ctrl+a XRemove current region
Ctrl+a QRemove all regions except current

Copy and Scrollback

KeyDescription
Ctrl+a [Enter copy/scrollback mode
SpaceStart selection (in copy mode)
EnterCopy selection (in copy mode)
Ctrl+a ]Paste copied text
Ctrl+a HToggle logging to file

Session Management

CommandDescription
screen -wipeClean dead sessions
Ctrl+a xLock session
screen -S work -X stuff 'ls^M'Send command to session (^M = Enter)
screen -S work -p 0 -X hardcopySave current window output

Useful Patterns

CommandDescription
screen -dmS job bash -lc 'long-command'Start detached background job
screen -D -RReattach if possible, otherwise create
screen -r work -p 2Attach directly to window 2
screen -LStart session with logging enabled

Configuration

File / CommandDescription
~/.screenrcUser configuration file
defscrollback 10000Increase scrollback history
hardstatus onEnable status line
startup_message offDisable startup message