Skip to main content

Keeping long jobs alive with screen

Quick reference for creating, detaching, reattaching and closing screen sessions and windows. Used to keep long-running jobs (exports, RMAN, patching) alive across SSH disconnections.

Create and use

screen
Opens a new session

screen -S session_name
Creates a named session (always do this, your future self will thank you)

Leave without killing the process

Ctrl + A then D
Detaches from the session (the process keeps running)

Return to the session

screen -ls
Lists active sessions

screen -r name_or_id
Reattaches to the session

screen -r -d name
Forces reattachment if the session is "stuck" on another terminal

Inside screen

Ctrl + A then C
Creates a new window

Ctrl + A then N
Next window

Ctrl + A then P
Previous window

Ctrl + A then "
Lists all windows

Ctrl + A then 0-9
Jumps straight to that window

Close

exit
Closes the current window

Ctrl + A then K
Kills the current window (no mercy)

screen -X -S name quit
Terminates the entire session

Scroll (very useful)

Ctrl + A then [
Enters scroll mode
Use arrow keys / PageUp / PageDown
Esc exits

Practical survival tips

Always use screen -S

Give sessions meaningful names

Before disconnecting from the server: Ctrl + A D (mandatory ritual)

CHEAT SHEET - SCREEN (paste into your mental notepad)

Sessions

screen -S app → creates a named session

screen -ls → lists sessions

screen -r app → returns to the session

screen -r -d app → forces reattachment

Ctrl + A D → leaves without killing anything

Windows

Ctrl + A C → new window

Ctrl + A N / P → next / previous

Ctrl + A " → lists windows

Ctrl + A 0-9 → switches directly

Control

Ctrl + A [ → scroll

exit → closes the window

Ctrl + A K → kills the window

screen -X -S app quit → kills everything