One screen session can contain several screen windows. A window runs another program instance.
To start a new screen session
$ screen [command]
If an explicit command is not given then a shell is started.
A session has a unique identifier by default following the following pattern:
pid.tty.host. You can give a more useful name (to reattach later) using
the following command
$ screen -R name [command]
A window has a numeric identifier.
From a running session you can enter command mode holding the control key and pressing the 'a' character. Command mode allows you to enter speial characters to: create new windows, detach from screen session, etc.
`<C-a>` : enters command mode from a running `screen` session.
When in command mode, one command is one character. After the command is executed then the program goes back to normal mode.
Use "space bar" to toggle selection to copy.
-list: List running
-r <session-id>: reattach to a screen session.
-R <session-id>: reattach to a screen session or create it first.
-RR <session-id>: like -R but resume the yungest if there are multiple possibilities (*).
-d <session-id>: detach a screen session
-D <session-id>: detach a screen session (logout if necessary)
(*): a session id is unique, however a partial session-id (without the pid prefix) can be specified. In this case there can be a conflict.
For example to detach a running screen session from the holding terminal and reattach it in the current one (given session-id: 123.pts-1.localhost)
$ screen -d -r pts-1
Screen can be extremely useful when is run above an SSH session because allows to:
We use "weechat-curses" program as an example.
ssh <host> -t screen -D -RR mysessionid top
The command, after login, will
-t) and connects it to the screen session
screensession named "weechat". It a session with that name exists, it will reattach to it (
To know if the current shell is running under screen or tmux check the STY and TMUX environment variables, respectively. If they are empty then you are not under a multiplexer.
Add the following to the
.bashrc file to have the information always in
if [ -n "$STY" ]; then export PS1="(s) $PS1"; fi if [ -n "$TMUX" ]; then export PS1="(t) $PS1"; fi