GNU Screen - Getting Started

Screen is an important tool especially for working remotely and running long tasks on the remote machine. In such scenarios, there is a possibility that the VPN connection could break in the middle of a task. GNU Screen allows you to start a window in your remote machine which is not tied to the life of your current terminal. This way even if you disconnect, your Screen will still continue to run on your remote machine and you can just re-attach to the same session once you re-connect.

Following are some basic commands to get you started :
  • Start screen - Just type "screen" into a Linux terminal. This will give you a window identical to a normal Linux terminal. You can send commands to the screen program by using CTRL + a. More on these commands below. Whatever you do now will be running inside screen.
  • Detach from Screen - CTRL + a + d. This will detach you from screen and take you to the terminal. Your screen session will continue to run in the background.
  • Re-attach to Screen - "screen -r". This will re-attach yourself to an existing screen session. In case, there are multiple screen sessions, then you need to pick the screen using its pid. The multiple screens will look as follows :
          There are several suitable screens on:
                            25779.pts-26.asterws0133 (10/16/2016 04:14:22 PM) (Detached)
                            20894.pts-27.asterws0133 (10/16/2016 01:19:11 PM) (Detached)
                            26605.pts-30.asterws0133 (10/15/2016 08:33:05 PM) (Detached)
          Type "screen [-d] -r [pid.]" to resume one of them.
          You can type "screen -r 25779" to attach to the first screen.
            • Open multiple windows in Screen - CTRL+a+c.
            • Close a window in Screen - "exit". If your screen only has one window, this will close it.
            • Switching between screen windows -
              • CTRL+a+n - next window
              • CTRL+a+p - previous window