Compilation of:
Start a new session with name:
screen -S <name>
List of running screen
sessions:
screen -ls
# or
screen -list
Attach to the running screen session (with name):
screen -x [session_name]
# or:
screen -r <session_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 default
Ctrl+a
(that's sometimes written ^a
). To send a literal Ctrl+a
to the programs in screen, use Ctrl+a
a
. This is useful when working
with screen within screen. For example Ctrl+a
a
n
will move screen
to a new window on the screen within screen.
Command | Description |
---|---|
Ctrl+a d |
Detach from the current screen session, and leave it running. Use screen -r to resume |
Ctrl+a D D |
Detach and logout |
exit |
Getting out from the screen session |
Command | Description |
---|---|
Ctrl+a c |
Create a new window (with shell) |
Ctrl+a Ctrl+a |
Toggle between current and previous region |
Ctrl+a <number> |
Change to window by number: opens window <number> |
Ctrl+a 0 |
Change to window by number: opens window 0 |
Ctrl+a ' <number or title> |
Change to window by number or name |
Ctrl+a n |
Change to next window in list |
Ctrl+a Space |
Change to next window in list |
Ctrl+a p |
Change to previous window in list |
Ctrl+a Backspace |
Change to previous window in list |
Ctrl+a " |
See window list |
Ctrl+a w |
Show window bar |
Ctrl+a A |
Rename the current window |
Ctrl+a a |
Sends Ctrl+a to the current window |
Command | Description |
---|---|
Ctrl+a S |
Split current region horizontally into two regions |
Ctrl+a | |
Split current region vertically into two regions |
Ctrl+a V |
Split current region vertically into two regions (for the vanilla vertical screen patch) |
Ctrl+a Tab |
Switch the input focus to the next region |
Ctrl+a X |
Close the current region |
Ctrl+a Q |
Close all regions but the current one |
Command | Description |
---|---|
Ctrl+a [ |
Enter Copy Mode (freely navigate buffer; use enter to select a range of text) |
Ctrl+a Esc |
Enter Copy Mode (freely navigate buffer; use enter to select a range of text) |
Space |
Toggle selection to copy |
Ctrl+a ] |
Paste text |
Command | Description |
---|---|
Ctrl+a ? |
See help: displays commands and their defaults |
Command | Description |
---|---|
Ctrl+a Ctrl+l |
Redraw window |
Ctrl+a M |
Monitor window for activity |
Ctrl+a _ |
Monitor window for silence |
Ctrl+a Ctrl+v |
Enter digraph (for producing non-ASCII characters) |
Ctrl+a x |
Lock (password protect) session |
Ctrl+a : |
Enter screen command |
Ctrl+a H |
Enable logging in the screen session |
Command | Description |
---|---|
Ctrl+u |
Half page up |
Ctrl+d |
Half page down |
Ctrl+b |
Back |
Ctrl+f |
Forward |
h , j , k , l |
Cursor left/down/up/right |
Command | Description |
---|---|
Ctrl+a : |
Enter to the command prompt of screen |
Ctrl+a :quit |
Closes all windows and closes screen session |
Ctrl+a :source ~/.screenrc |
Reloads screenrc configuration file (can alternatively use /etc/screenrc) |
It is possible to get stuck in a nested screen session. A common scenario:
you start an SSH session from within a screen session. Within the SSH session,
you start screen. By default, the outer screen session that was launched first
responds to Ctrl+a
commands. To send a command to the inner screen session,
use Ctrl+a
a
, followed by your command. For example:
Command | Description |
---|
Ctrl+a
a
d
| Detaches the inner screen session.Ctrl+a
a
K
| Kills the inner screen session.
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'