Cheatsheet: GNU Screen

Last updated 2026-09-19

Basic Commands

Start a new screen session

screen

Start a new session with a specific name

screen -S <session_name>

List running screen sessions

screen -ls

Attach to a detached session

screen -r <session_name>

Detach from a session

Ctrl + a d

Session management in depth

Force-detach a session that's stuck attached elsewhere, then reattach it here.

screen -d -r <session_name>

Force a full detach (kills the other attachment outright) if -d -r doesn't respond.

screen -D -r <session_name>

Attach to a session while leaving it attached elsewhere too, for shared viewing/control.

screen -x <session_name>

Kill a named session from outside it, without attaching first.

screen -X -S <session_name> quit

Terminate a session from inside it by exiting every window, or with the :quit command.

exit

# or, inside screen:
Ctrl + a :quit

Scrollback and copy mode

Enter copy mode to scroll back through a window's output history.

Ctrl + a [

Once in copy mode, use arrow keys or Page Up/Page Down to scroll; press Esc or q to exit.

Ctrl + a [
# then: Up / Down / PgUp / PgDn
# then: Esc  (exit copy mode)

Select and copy text: mark the start, move to the end, mark it again, then paste elsewhere.

Ctrl + a [       # enter copy mode
# move cursor, press Space to start selection
# move cursor, press Space again to copy
Ctrl + a ]       # paste the copied text

Increase the scrollback buffer size (default is small) in ~/.screenrc.

echo 'defscrollback 10000' >> ~/.screenrc

Managing Windows

Create a new window

Ctrl + a c

Switch to the next window

Ctrl + a n

Switch to the previous window

Ctrl + a p

Close the current window

Ctrl + a k

Split the current window vertically

Ctrl + a |

Miscellaneous

Reattach a session with multiple users

screen -x <session_name>

Send a command to a specific window

screen -X -p <window_number> <command>

Lock the screen session

Ctrl + a x

Installation

Install with yum (CentOS/RHEL)

sudo yum install screen

Install with apt (Debian/Ubuntu)

sudo apt-get install screen

Install with brew (Mac)

brew install screen

FAQ