Screen for macOS Cheat Sheet
Created: 2025-04-03 01:12:24 | Last updated: 2025-04-03 01:12:24 | Status: Public
Escape Key Basics
All screen
commands are prefixed by an escape key, by default C-a
(that’s Control-a, sometimes written ^a
). To send a literal C-a
to the programs in screen, use C-a a
. This is useful when working with screen within screen. For example C-a a n
will move screen to a new window on the screen within screen.
Getting In
Command | Description |
---|---|
screen -S <name> |
Start a new screen session with session name |
screen -ls |
List running sessions/screens |
screen -x |
Attach to a running session |
screen -r <name> |
Attach to a running session with name |
screen -dRR |
The “ultimate attach” - Attaches to a screen session. If the session is attached elsewhere, detaches that other display. If no session exists, creates one. If multiple sessions exist, uses the first one. |
Getting Out
Command | Description |
---|---|
screen -d <name> |
Detach a running session |
C-a d |
Detach |
C-a D D |
Detach and logout (quick exit) |
C-a : quit |
Exit screen or exit all of the programs in screen |
C-a C-\ |
Force-exit screen (not recommended) |
Help
Command | Description |
---|---|
C-a ? |
See help - Lists keybindings. The man page is the complete reference, but it’s very long. |
Window Management
Command | Description |
---|---|
C-a c |
Create new window |
C-a C-a |
Change to last-visited active window (commonly used to flip-flop between two windows) |
C-a <number> |
Change to window by number (only for windows 0 to 9) |
C-a ' <number or title> |
Change to window by number or name |
C-a n or C-a <space> |
Change to next window in list |
C-a p or C-a <backspace> |
Change to previous window in list |
C-a " |
See window list (allows you to select a window to change to) |
C-a w |
Show window bar (if you don’t have window bar) |
C-a k |
Kill current window (not recommended) |
C-a \ |
Kill all windows (not recommended) |
C-a A |
Rename current window |
Split Screen
Command | Description |
---|---|
C-a S |
Split display horizontally |
C-a \| |
Split display vertically or C-a V (for the vanilla vertical screen patch) |
C-a tab |
Jump to next display region |
C-a X |
Remove current region |
C-a Q |
Remove all regions but the current one |
Scripting
Send a command to a named session:
screen -S <name> -X <command>
Create a new window and run ping example.com:
screen -S <name> -X screen ping example.com
Stuff characters into the input buffer using bash to expand a newline character:
screen -S <name> [-p <page>] -X stuff $'quit\r'
A full example:
# run bash within screen
screen -AmdS bash_shell bash
# run top within that bash session
screen -S bash_shell -p 0 -X stuff $'top\r'
# ... some time later
# stuff 'q' to tell top to quit
screen -S bash_shell -X stuff 'q'
# stuff 'exit\n' to exit bash session
screen -S bash_shell -X stuff $'exit\r'
Miscellaneous
Command | Description |
---|---|
C-a C-l |
Redraw window |
C-a [ |
Enter copy mode or C-a <esc> (also used for viewing scrollback buffer) |
C-a ] |
Paste |
C-a M |
Monitor window for activity |
C-a _ |
Monitor window for silence |
C-a C-v |
Enter digraph (for producing non-ascii characters) |
C-a x |
Lock (password protect) display |
C-a : |
Enter screen command |
C-a H |
Enable logging in the screen session |