D   A   T   A   W   O   K

Creation: August 28 2017
Modified: February 05 2022


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.

Core commands

Split screen commands

Clipboard commands

Use "space bar" to toggle selection to copy.

Core command line options

(*): 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

Run screen in a remote server

Screen can be extremely useful when is run above an SSH session because allows to:

  1. Execute multiple programs in a single SSH session
  2. Disconnect and reconnect later to an interactive program or to avoid waiting for a long run operation.

We use "weechat-curses" program as an example.

ssh <host> -t screen -D -RR mysessionid top

The command, after login, will


Extra tip

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 the prompt.

if [ -n "$STY" ]; then
    export PS1="(s) $PS1";
if [ -n "$TMUX" ]; then
    export PS1="(t) $PS1";

The default statusbar may be little lacking. You may find this one more helpful:


hardstatus off
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%uu)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W} %c %{g}]'


Proudly self-hosted on a cheap Raspberry Pi