Hotkeys
The prefix is Ctrl+a, then a key:
Keeps a terminal session alive on the server after an SSH drop; sessions live in memory and don't survive a reboot.
screen -S name
new named session
screen -ls
list sessions
screen -r name
attach to a session
screen -d -r name
detach from another terminal and attach here
Ctrl+a d
detach — the session keeps running
screen -dmS job cmd
start detached right away, for scripts
-S gives the session a name instead of a pid number — without it,
screen -ls shows hard-to-read identifiers. -d -r solves the common
"session busy on another terminal" problem: it detaches it there first,
then attaches it here.
| Option | What it does | Example |
|---|---|---|
-S name |
Name the session instead of using its pid — easier to find later. | screen -S work |
-ls |
List running sessions and their state (Attached/Detached). | screen -ls |
-r name |
Reattach to a detached session by name. | screen -r work |
-d |
Detach the session from its current terminal (combine with -r to steal it). | screen -d -r work |
-dmS name |
Start a command directly in a detached session — handy for scripts and cron. | screen -dmS job long-running-command |
-X command |
Send a control command to a named session without attaching to it. | screen -X -S job quit |
Nothing found. Try a shorter query.
The prefix is Ctrl+a, then a key:
~/.screenrc (common settings):
No such session (closed/rebooted). screen -ls shows what exists.
Sessions live in memory — a reboot kills them (for services that must
survive, use systemd).
The session is "stuck" to another terminal: screen -d -r work (detach
and attach).
Ctrl+a then C (clear) or reconnect. Check $TERM
(xterm-256color).
screen scrolls through copy mode by default (Ctrl+a [). Increase the
defscrollback buffer in ~/.screenrc. For mouse/panes, tmux is more
convenient.
Found an inaccuracy? Report an error in the article