screen — Terminal Multiplexer for Persistent Sessions
Practical guide to screen: start, detach and reattach sessions, split windows and keep processes running across SSH disconnects.
screen is a terminal multiplexer: it wraps several virtual terminals into a single session that you can detach (Ctrl+a d) at any time and reattach later. That makes it indispensable on servers – kick off a long build or backup over SSH and it keeps running even if the connection drops or you log out. This guide walks you through the commands for sessions, windows, split regions and the .screenrc.
Sessions
screen — Start a new unnamed session.
screenscreen -S <name> — Start a new named session.
screen -S projectscreen -ls — List all active screen sessions.
screen -lsscreen -r <name> — Reattach to a detached session.
screen -r projectscreen -r — Reattach to the only detached session (fails if multiple exist).
screen -rscreen -d -r <name> — Detach a session from elsewhere and reattach it here.
screen -d -r projectscreen -x <name> — Attach to a session that is already attached (multi-display mode).
screen -x projectscreen -d <name> — Detach a session remotely without reattaching.
screen -d projectscreen -X -S <name> quit — Kill a session by name from outside.
screen -X -S project quitSession Key Bindings (Prefix: Ctrl+a)
Ctrl+a d — Detach from the current session (session keeps running).
Ctrl+a dCtrl+a \ — Kill all windows and terminate the session.
Ctrl+a \Ctrl+a : sessionname <name> — Rename the current session.
Ctrl+a : sessionname myprojectCtrl+a ? — Show all key bindings (help).
Ctrl+a ?Windows
Ctrl+a c — Create a new window.
Ctrl+a cCtrl+a A — Rename the current window.
Ctrl+a ACtrl+a " — Show a list of all windows and select one.
Ctrl+a "Ctrl+a n — Switch to the next window.
Ctrl+a nCtrl+a p — Switch to the previous window.
Ctrl+a pCtrl+a <number> — Switch to window by number (0-9).
Ctrl+a 3Ctrl+a Ctrl+a — Toggle between the current and last window.
Ctrl+a Ctrl+aCtrl+a k — Kill the current window (with confirmation).
Ctrl+a kCtrl+a w — Show a brief list of windows in the status bar.
Ctrl+a wSplit Regions
Ctrl+a S — Split the screen horizontally (top/bottom).
Ctrl+a SCtrl+a | — Split the screen vertically (left/right).
Ctrl+a |Ctrl+a Tab — Move focus to the next region.
Ctrl+a TabCtrl+a X — Close the current region (window keeps running).
Ctrl+a XCtrl+a Q — Close all regions except the current one.
Ctrl+a QCopy & Scrollback
Ctrl+a [ — Enter copy/scrollback mode. Navigate with arrow keys or vi keys.
Ctrl+a [Space — Set the start of the selection (in copy mode). Press again to copy.
SpaceCtrl+a ] — Paste the copied text.
Ctrl+a ]Ctrl+a Esc — Enter copy mode (alternative to Ctrl+a [).
Ctrl+a EscCtrl+a h — Write a hardcopy of the current screen to a file.
Ctrl+a hCtrl+a H — Toggle logging of the current window to a file.
Ctrl+a HMiscellaneous
Ctrl+a : — Enter command mode (type screen commands directly).
Ctrl+a : hardstatus alwayslastlineCtrl+a i — Show information about the current window.
Ctrl+a iCtrl+a t — Show the system time and host information.
Ctrl+a tCtrl+a x — Lock the screen session (requires password to unlock).
Ctrl+a xCtrl+a Z — Reset the terminal (useful after garbled output).
Ctrl+a Zscreen -L -S <name> — Start a session with automatic logging to screenlog.0.
screen -L -S logged-sessionConfiguration (~/.screenrc)
defscrollback <n> — Set the scrollback buffer size (number of lines).
defscrollback 10000startup_message off — Disable the startup splash message.
startup_message offhardstatus alwayslastline — Always show the status line at the bottom.
hardstatus alwayslastline "%{= kw}%-w%{= BW}%n %t%{-}%+w %-= %D %d.%m.%Y %c"shell -$SHELL — Use the default login shell for new windows.
shell -/bin/bashbind <key> <command> — Bind a custom key to a screen command.
bind | split -vscreen -t <title> <n> <command> — Auto-create named windows with commands in .screenrc.
screen -t editor 0 vim
screen -t server 1 ./run.sh
screen -t logs 2 tail -f app.logtermcapinfo xterm* ti@:te@ — Enable mouse scrolling in xterm-compatible terminals.
termcapinfo xterm* ti@:te@ Conclusion
screen keeps your work alive: a detached session keeps running in the background whether your SSH connection drops or you log out – screen -r <name> puts you right back, and screen -x even lets several people watch the same session. For everyday use screen -S, Ctrl+a d, screen -ls and screen -r cover most of it. If you only need to decouple a single command from the terminal, nohup is leaner; if you want more modern window management, mouse support and more active maintenance, take a look at tmux. screen is the older, less actively maintained classic these days – but it ships pre-installed on virtually every Unix system and does its job reliably.
Further Reading
- GNU Screen Manual – official reference manual with all options and key bindings
- Arch Wiki: GNU Screen – practical guide to configuration and day-to-day usage