Cheat Sheet

screen Command Linux Cheat Sheet

GNU screen keeps a shell running on the server after you disconnect: detach, log off, and reattach later with everything still going. This sheet covers the session commands, the Ctrl+a shortcuts, copy mode, background jobs, serial ports, and how screen maps to tmux.

Last updated September 11, 2026

Detach and Reattach

Ctrl+a is screen's command key: press Ctrl+a, release, then the letter. Detaching leaves everything running; is what actually ends things.

CommandWhat it does
Detach, leaving the session and its jobs running
Detach and log out of the shell that started screen
Reattach to the detached session
Reattach to a session by name (or PID)
Detach it from wherever it is attached, then reattach here
Attach without detaching anyone; both of you see the same screen
Reattach to the first session found, creating one if none exist
Detach a session from outside it
Close the current window; closing the last one ends the session

A dropped SSH connection detaches you automatically, so a long job inside screen survives it; gets you back in. To stop the drops themselves, see ssh broken pipe.

Sessions

CommandWhat it does
Start a new session
Start a session named deploy, which beats PIDs for reattaching
List sessions and whether each is Attached or Detached
Start a detached session running a command (scripts, cron)
Type a command into a session from outside
Rename the current session
Remove sessions marked Dead from the list

Run in the Background

(or with a name) starts a session already detached, which is how scripts, cron jobs, and game servers get a shell that outlives the login.

CommandWhat it does
Run a script in a detached session named backup
Keep the window open after the command exits, so you can read the error
Same, logging output to screenlog.0
Open another window running a command in a session that already exists
Send a line to the session as if you typed it
Send it to window 0 specifically (how people stop a Minecraft server)
Check whether the background session is still alive

A detached session is owned by your login, so it dies with a reboot and with an aggressive user-session cleanup. Anything that must come back on its own belongs in a service unit rather than screen.

Kill a Session

CommandWhat it does
Kill the current window (asks first)
Kill every window and end the session (asks first)
Kill a session from outside, without attaching
Close windows one at a time; the session ends with the last one

Kill every detached session at once:

screen -ls | grep Detached | cut -d. -f1 | xargs -r kill

Scrolling and Copy Mode

PgUp and the mouse wheel talk to your terminal, not to screen. Scrolling back happens in copy mode.

CommandWhat it does
or Enter copy mode
, , , Scroll (, , , also work)
and Jump to the top or bottom of the buffer
and Search forward and backward
Start selecting; a second or copies and exits
or Leave copy mode without copying
Paste what you copied
Bigger buffer for the current window

The default buffer is only 100 lines. Put in so every window starts with real history.

Windows

Windows are full-screen tabs inside one session.

CommandWhat it does
New window
and Next and previous window
to Jump to a window by number
Pick a window from a list
Show the window list in the message line
Rename the current window
Toggle between the two most recent windows
Alert when this window shows activity
Alert when this window goes silent for 30 seconds
Kill the window (asks first)

Split Screen

A new region starts empty: move into it with , then open a window in it.

CommandWhat it does
Split top and bottom (capital S)
Split left and right
Move to the next region
Open a new window in the empty region ( picks an existing one)
Close the current region; its window keeps running
Close every region except the current one
Set the current region to 20 lines
Grow or shrink it by 5 ( the other way)
Give every region the same size
Redraw after the terminal window itself changed size

Keyboard Shortcuts

The rest of the keys worth knowing.

KeyAction
List every keybinding
Send a literal Ctrl+a through (start of line in bash)
Command prompt for screen's own commands
Lock the session behind your password
Start or stop logging the window
Write a snapshot of the visible window to hardcopy.0
List the displays attached to this session

Serial Ports

screen doubles as a serial terminal, which is the main thing it does that tmux does not. Settings default to 8N1; give the baud rate after the device.

CommandWhat it does
Serial console at 115200 baud (Raspberry Pi, ESP32, most dev boards)
Arduino-style boards that show up as ACM
macOS device names live under
Close the serial session and free the port

Detaching with keeps the port locked, so end serial sessions with . Permission denied on the device means your user is not in the right group: , then log in again.

Logging

CommandWhat it does
Log everything to screenlog.0 in the current directory
Log to a file you name (screen 4.6 and newer)
Start or stop logging from inside a session
One-off snapshot of the visible window to hardcopy.0
In : log every window from the start

Install

"screen: command not found" means the package is missing, which is normal on minimal images and containers.

CommandWhat it does
Debian, Ubuntu, Raspberry Pi OS
Fedora, RHEL, Rocky, AlmaLinux ( on CentOS 7)
Alpine
Arch
macOS, replacing the 2006-era build Apple ships
Print the version, to confirm which one you got
Show which copy of screen is first in

macOS still has at version 4.00.03, which is missing and a lot of the copy-mode keys. Homebrew's build lands in ahead of it.

PuTTY and WSL

Windows has no screen of its own. You either run it on the Linux box you connect to, or run it locally under WSL.

CommandWhat it does
then Run screen locally in a WSL distro (install it there with )
Run it on the remote host after connecting; PuTTY only carries the keys
Send a literal Ctrl+a, needed because PuTTY passes Ctrl+a straight through

PuTTY has its own serial mode, so on Windows you pick a COM port there instead of . The PuTTY cheat sheet covers the Windows side.

screen vs tmux

The keys map almost one to one, so switching either way is cheap. tmux has better splits, a status bar, and active development; screen is preinstalled more often and handles serial ports. The tmux cheat sheet covers the other side in full.

screentmux
, ,
and and

Gotchas

  • Detach is not exit. keeps everything running; closes the window, and the last window takes the session with it ("[screen is terminating]").
  • The scrollback buffer defaults to 100 lines. Add to before you need it, not after.
  • screen eats Ctrl+a, which bash uses for start of line. Press to send it through, or move the command key with in .
  • "There is no screen to be resumed" while shows a session Attached means a dead client is holding it. takes it over.
  • screen inside screen (a session on the far end of an SSH window): detaches the inner one, the outer.
  • Sessions do not survive a reboot. screen protects you from disconnects, not from restarts; anything that must outlive a reboot belongs in a systemd service.

screen FAQ

How do I exit the screen command?

There are three exits and they do different things. Ctrl+a then d detaches: the shell and every job in it keep running, screen -ls shows the session as Detached, and screen -r brings it back. Typing exit (or Ctrl+d) closes the current window, and when the last window goes the session ends for good and prints screen is terminating. Ctrl+a then backslash kills every window at once after a confirmation. From outside, screen -S deploy -X quit ends a session without attaching to it first. If Ctrl+a d does nothing you are probably not inside screen: run echo $STY, which prints the session name inside screen and nothing outside it.

How do I scroll up inside screen?

Press Ctrl+a then [ to enter copy mode, scroll with PgUp, PgDn, or the arrow keys, and press q to get back to a live prompt. The mouse wheel usually scrolls your terminal's own buffer instead, which mixes windows together, so copy mode is the reliable way. The real catch is the buffer size: screen keeps only 100 lines by default. Put defscrollback 10000 in ~/.screenrc, or run Ctrl+a :scrollback 10000 for the current window, and the history becomes worth scrolling.

How do I kill all screen sessions at once?

pkill screen ends every session your user owns, attached ones included, so check screen -ls before running it. For detached sessions only, pipe the list into kill: screen -ls | grep Detached | cut -d. -f1 | xargs -r kill. The PID is the number before the dot in each entry, so you can also kill them one at a time from that list. A single named session dies with screen -S deploy -X quit, no attaching needed. screen -wipe is not a kill: it only drops entries already marked Dead off the list.

Why does screen say command not found?

screen is not installed. Minimal images, containers, and fresh cloud instances usually ship without it, and some distros dropped it from the default set. Install it with sudo apt install screen on Debian, Ubuntu, and Raspberry Pi OS, sudo dnf install screen on Fedora, RHEL, and Rocky, sudo apk add screen on Alpine, or sudo pacman -S screen on Arch. macOS carries an ancient 4.00.03 build at /usr/bin/screen; brew install screen puts a current one ahead of it in PATH. Windows has no screen, so run it inside WSL or on the Linux host you SSH into. With no sudo rights, check whether tmux is already there.

Should I use screen or tmux?

For plain detach and reattach over SSH, either works and the keys map almost one to one: screen -S is tmux new -s, screen -r is tmux attach, and Ctrl+a d is Ctrl+b d. tmux is the better multiplexer, with real pane splitting, a status bar, a scriptable command language, and active development. screen keeps two advantages: it is preinstalled on more old and minimal systems, and it doubles as a serial terminal with screen /dev/ttyUSB0 115200, which tmux cannot do. On a box that has both, pick tmux; on a box you cannot install anything on, screen is usually already there.

Related cheat sheets