GNU Screen

Screen is a virtual terminal multiplexer, which allows the creation and use of multiple terminal sessions within a single window or remote session. A user can easily manage multiple tasks and command line programs on a Linux server without the clutter of many open windows. Screen sessions can be detached, staying active in the background, and reattached at a later point in time.

Installing Screen

GNU Screen is available in the default package repositories of Redhat and Centos Linux, and can be installed via the 'yum' command.

yum install screen

Using Screen

To start a screen session, simply execute the command:

screen

You'll then be at a new shell prompt, a window, running under screen. Execute a command such as 'top', then create new window with the shortcut "CTRL+a" then "c". You'll be presented with a new shell session, while 'top' is still running on the previous. You can switch between the sessions with "CTRL+a" "p" and "CTRL+a" "n". A list of all windows can be shown, with the shortcut "CTRL+A" '"' (double quotation).

To easily identify what each screen window is being used for, you can assign names with the shortcut "CTRL+a" "A" (case sensitive).

Detached From and Resume Sessions

To detach from the current screen session, simply use the shortcut "CTRL+a" "d". You'll then be placed back to the server shell outside of screen. You can list all screen sessions via the the '-ls' switch to screen. For example:

[root@host ~] screen -ls
There is a screen on:
5035.pts-1.vps (Detached)
1 Socket in /var/run/screen/S-root.

A session can be resumed, attached, with the '-x session_id' switch to the screen command.

screen -x 5035

Using the '-R' switch will resume the first available session, and is the easiest to use if there's only one session in use.

Common Shortcuts

All screen shortcuts are started via "CTRL+a". Below is a list of the most commonly used shortcuts

  • c - Create a new window
  • a - Switch to previously used window
  • n - Switch to next window
  • p - Switch to previous window
  • " - List all windows
  • Escape - Scroll current window with arrow and pageup/down keys
  • d - Detach from the current screen session
  • K - Kill the current window

 

Please refer to the screen documentation for further shortcuts and options.