start a new screen session with session name | screen -S<name> |
list running sessions/screens | screen -ls |
attach to a running session | screen -x |
attach to sessionname | screen -r<name> |
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.) |
All screen commands are prefixed by an escape key, by defaultC-a
(that's Control-a, sometimes written^a
). To send a literalC-a
to the programs in screen, useC-a a
. This is useful when working with screen within screen. For exampleC-a a n
will move screen to a new window on the screen within screen.
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 <number> (only for windows 0 to 9) |
change to window by number or name | C-a ' <number or title> |
change to next window in list | C-a n orC-a <space> |
change to previous window in list | C-a p orC-a <backspace> |
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 |
To any sessionname,
send a command to a named session | screen -S<name> -X<command> |
create a new window and runping example.com | screen -S<name> -X screenping example.com |
stuff characters into the input buffer using bash to expand a newline character (from here) | screen-S<name>[-p<page>]-X stuff $'quit\r' |
A full example:
# run bash within screenscreen-AmdS bash_shellbash# run top within that bash sessionscreen-S bash_shell-p0-X stuff $'top\r' # ... some time later # stuff 'q' to tell top to quitscreen-S bash_shell-X stuff'q'# stuff 'exit\n' to exit bash sessionscreen-S bash_shell-X stuff $'exit\r'
In copy mode, one can navigate the scrollback buffer in various ways:
half page up | C-u | half page down | C-d | |
back | C-b | forward | C-f | |
cursor left/down/up/right | h/j/k/l |