Session Management
Create & List Sessions
screen # new unnamed session screen -S work # new session named "work" screen -ls # list all sessions screen -list # same as -ls
Session Commands
screen -S nameStart new named session
screen -r nameReattach to detached session
screen -x nameAttach to already-attached session (share)
screen -d nameDetach a remote session
screen -d -r nameDetach elsewhere, reattach here
screen -D -RRForce detach and reattach (aggressive)
screen -lsList all sessions with PIDs
screen -wipeClean up dead sessions
Windows
Window Basics
Ctrl-a cCreate new window
Ctrl-a nNext window
Ctrl-a pPrevious window
Ctrl-a 0-9Switch to window by number
Ctrl-a "List all windows (interactive)
Ctrl-a 'Switch to window by name/number
Ctrl-a ARename current window
Ctrl-a kKill current window
Window Management
Ctrl-a wShow window list in status line
Ctrl-a Ctrl-aToggle between last two windows
Ctrl-a NShow window number and name
exit / Ctrl-dClose window (exit shell)
Split & Regions
Split Commands
Ctrl-a SSplit horizontally (top/bottom)
Ctrl-a |Split vertically (left/right)
Ctrl-a TabMove focus to next region
Ctrl-a XClose current region
Ctrl-a QClose all regions except current
Region Workflow
Ctrl-a S # split horizontal Ctrl-a Tab # move to new region Ctrl-a c # create window in region Ctrl-a :resize 20 # set region to 20 lines
Copy Mode
Scrollback & Copy
Ctrl-a [Enter copy/scrollback mode
SpaceStart/end selection (in copy mode)
EnterCopy selection and exit copy mode
Ctrl-a ]Paste copied text
h/j/k/lMove cursor (vi keys in copy mode)
Ctrl-u / Ctrl-dScroll up/down half page
/ or ?Search forward/backward
EscExit copy mode
Copy Workflow
Ctrl-a [ # enter copy mode Space # mark start (navigate first) Space # mark end + copy (navigate first) Ctrl-a ] # paste into current window
Detach & Reattach
Detach
Ctrl-a dDetach current session
Ctrl-a D DDetach and log out
Ctrl-a zSuspend screen (like Ctrl-Z)
screen -d PIDRemotely detach session by PID
Reattach
screen -r # reattach (if only one session) screen -r work # reattach by name screen -r 12345 # reattach by PID screen -d -r work # steal session from other terminal
Persistent Workflows
# Start long-running task, detach, reconnect later screen -S build make -j4 all # start build Ctrl-a d # detach, go home screen -r build # reattach later
Sharing
Multi-User Mode
# Host enables multiuser Ctrl-a :multiuser on Ctrl-a :acladd alice # grant access to user alice # Alice attaches screen -x hostuser/sessionname
Access Control
:multiuser onEnable multi-user mode
:acladd userGrant user full access
:aclchg user -w '#'Make user read-only (all windows)
:acldel userRemove user access
screen -x user/sessAttach to shared session
Configuration
~/.screenrc Essentials
startup_message off # skip splash screen defscrollback 10000 # scrollback buffer lines hardstatus alwayslastline hardstatus string '%{gk}%H %{wk}%?%-Lw%?%{bw}%n*%f %t%{wk}%?%+Lw%?' shell -$SHELL # use login shell
Useful Settings
startup_message offSuppress startup message
defscrollback NSet scrollback buffer (default 100)
escape ^BbChange prefix key to Ctrl-b
shelltitle '$ |bash'Auto-set window titles
caption always '%n %t'Always show caption with window info
autodetach onAuto-detach on hangup (default on)
vbell onUse visual bell instead of audible
Common Patterns
Development Setup
# Auto-create windows in .screenrc screen -t editor 0 vim screen -t server 1 python -m http.server screen -t shell 2 bash select 0 # start on editor window
Logging & Monitoring
Ctrl-a H # toggle logging to screenlog.N Ctrl-a M # monitor window for activity Ctrl-a _ # monitor window for silence
Quick Reference
Ctrl-a ?Show all key bindings
Ctrl-a :helpBuilt-in help
Ctrl-a :source fileLoad config file
Ctrl-a :screen cmdRun command in new window
Ctrl-a :quitKill all windows and exit session