Screen

Commands

  • Installation: yum install screen
  • List running screen sessions: screen -ls
  • Set the title, a meaningful name for the session (removes the default [tty.host] suffix) and start in "detached" mode: screen -S monitoring -t top -dm top
  • Send the specified command to a running screen session: screen -S monitoring -t htop -X screen htop
  • Start a remote screen session through SSH: ssh <username>@<hostname> screen -S top -t top -dm top
  • Reattach a session and if necessary detach it first: screen -d -r 9096.pts-9.<hostname>
  • Connect to a remote host (works only if there is only one screen session): ssh -t <username>@<hostname> screen -RD
  • Connect to a remote host with a specific screen session: ssh -t <username>@<hostname> screen -R [sessionname/PID]
  • Rename a session: screen -S top -X sessionname iotop
  • Turn on automatic output logging (~/screenlog., see the file with cat, more or less -r): screen -L
  • Stop detached screen session: screen -S 9871.pts-1.<hostname> -X quit
  • Sharing the sessions between two accounts:
Ctrl+a, then type :multiuser on
Ctrl+a, then type :acladd daniel (daniel is the username of the person who will connect to your screen session)

In the other terminal

screen -x root/12490.pts-0.<hostname> (root is the username of the person who is sharing the screen session)

Be sure to use Ctrl+a, d otherwise the session will end for both accounts !

Shortcuts

| Command                     | Description                                                                            |
|-----------------------------|----------------------------------------------------------------------------------------|
| Ctrl+a c                    | Create new window                                                                      |
| Ctrl+a k                    | Kill the current window / session                                                      |
| Ctrl+a w                    | List all windows                                                                       |
| Ctrl+a 0-9                  | Go to a window numbered 0 9, use Ctrl+a w to see number                                |
| Ctrl+a Ctrl+a               | Toggle / switch between the current and previous window                                |
| Ctrl+a S                    | Split terminal horizontally into regions and press Ctrl+a c to create new window there |
| Ctrl+a tab                  | Move to next region                                                                    |
| Ctrl+a D (Shift-d)          | Power detach and logout                                                                |
| Ctrl+a d                    | Detach but keep shell window open                                                      |
| Ctrl-a Ctrl-\               | Quit screen                                                                            |
| Ctrl-a ?                    | Display help screen i.e. display a list of commands                                    |
| Ctrl-a ESC                  | Scroll up and down terminal                                                            |
| Ctrl-a A                    | Changes window session name                                                            |
| Ctrl-a H                    | Toggles logging on and off                                                             |
| Ctrl-a "                    | Menu listing of all sessions                                                           |
| Ctrl+a n                    | Toggle to next window                                                                  |
| Ctrl+a p                    | Toggle to previous window                                                              |
| Ctrl+a i                    | Display window information                                                             |
| C-a :                       | Enter command line mode                                                                |
| Ctrl+a :resize              | Resize region                                                                          |
| Ctrl+a :fit                 | Fit screen size to new terminal size. You can also hit Ctrl+a F for the the same task  |
| Ctrl+a :remove              | Remove / delete region. You can also hit Ctrl+a X for the same taks                    |
| Ctrl+a :sessionname Session | Rename session                                                                         |                                                                

Links