Skip to content

Instantly share code, notes, and snippets.

@MeenachiSundaram
Last active August 7, 2019 18:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MeenachiSundaram/8def7d45339a10539e9cf1bb016d5621 to your computer and use it in GitHub Desktop.
Save MeenachiSundaram/8def7d45339a10539e9cf1bb016d5621 to your computer and use it in GitHub Desktop.
screen

SCREEN Quick Reference

Getting in

Description Command
start a new screen session with session name screen -S
list running sessions/screens screen -ls
attach to a running session screen -x
attach to session name screen -r
the “ultimate attach” screen -dRR (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.)

Escape key

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 nwill move screen to a new window on the screen within screen.

Getting out

Description Command
detach C-a d
detach and logout (quick exit) C-a D D
exit screen C-a \ Exit all of the programs in screen. (not recommended)
force-exit screen C-a C-\ (not recommended)
getting out of the screen session exit

Window Management

Description Command
create new window C-a c
change to last-visited active window C-a C-a (commonly used to flip-flop between two windows)
change to window by number C-a  (only for windows 0 to 9)
change to window by number or name C-a '
change to next window in list C-a n or C-a
change to previous window in list C-a p or C-a
see window list C-a " (allows you to select a window to change to)
show window bar C-a w (if you don't have window bar)
close current window Close all applications in the current window (including shell)
kill current window C-a k (not recommended)
kill all windows C-a \ (not recommended)
rename current window C-a A

Split Screen

Description Command
split display horizontally C-a S
split display vertically C-a
jump to next display region C-a tab
remove current region C-a X
remove all regions but the current one C-a Q

Clipboard and Navigation

Description Command
freely navigate buffer C-a [ or C-a
toggle selection to copy space
paste C-a ]

Help

Description Command
See help C-a ? (lists keybindings)

Scripting

To any session name,

Description Command
send a command to a named session screen -S  -X 
create a new window and run ping example.com screen -S  -X screen ping example.com
stuff characters into the input buffer, using bash to expand a newline character screen -S [-p ] -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'

Misc

Description Command
redraw window C-a C-l
monitor window for activity C-a M
monitor window for silence C-a _
enter digraph (for producing non-ASCII characters) C-a C-v
lock (password protect) session C-a x
enter screen command C-a :
enable logging in the screen session C-a H

Scrollback-buffer

In copy mode, one can navigate the scrollback buffer in various ways:

Description Command
half page up C-u
back C-b
cursor left/down/up/right h/j/k/l
half page down C-d
forward C-f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment