Screen is a simple utility that maintains a session on the server that you can reattach to, so you don’t need to maintain a connection, or, if you get disconnected, you can reattach to your running session.
To start, type
screen
or, to name the session:
screen -S my_session_name
To detach from a session.
Press
Ctrl-a
then d
. This leaves the session running in the background. To reattach to a session (if it’s the only screen session you have running)-
screen -r
If you have multiple detached sessions, you’ll need to reattach by specifying the session ID or name:
screen -r <session_id>
screen -r my_session_name
List active sessions
screen -ls
Managing Windows within a Session:
All
screen
commands within a session are prefaced with Ctrl-a
.
- Create a new window:
Ctrl-a
thenc
- Switch to the next window:
Ctrl-a
thenn
- Switch to the previous window:
Ctrl-a
thenp
- Switch to a specific window by number:
Ctrl-a
then0
(or the desired window number) - List all windows:
Ctrl-a
then"
(double quote) - Rename the current window:
Ctrl-a
thenA
- Kill the current window:
Ctrl-a
thenk
Some more advanced features:
- Split screen horizontally:
Ctrl-a
thenS
- Split screen vertically:
Ctrl-a
then|
- Navigate between split regions:
Ctrl-a
thenTab
- Enter copy mode (for scrolling and selecting text):
Ctrl-a
then[
- Paste copied text:
Ctrl-a
then]