Gnu Screen Usage

Gnu Screen is a helpful Linux utility which functions as a virtual terminal manager. With it you can manage multiple terminal sessions and detach/reconnect to sessions as needed in your workflow. The virtual terminals will continue to run and insulate you from unexpected disconnections and logouts.

Install

# Debian/Ubuntu
sudo apt-get install screen
# RHEL/Fedora/OEL
sudo yum install screen

Starting

screen
If you are sharing a machine with multiple other users you can provide your own session name which will help with tracking and sorting through multiple sessions. Or if you are handing off responsibility to someone else you can tag with a task name or somethign meaningful.
screen -S mytask

Detaching

Screen is good insurance against a shaky connection. If your connection is interrupted, Screen detaches the session but keeps running. You can resume by following the commands in the Resuming Screen Sessions section below. If you want to force a detach from your screen session hit "Ctrl-a" followed by hitting "d".

Using Virtual Terminals

After you start Screen you will be logged into a single virtual terminal. This single terminal is useful as-is to protect you from connection errors.

While connected to Screen these special commands are initiated by pressing "Ctrl-a" (Control + a at the same time) followed by another letter or number.

  • "Ctrl-a" c - Create a new window.
  • "Ctrl-a" n - Go to Next window. If you have more than 1 window available this will cycle through them.
  • "Ctrl-a" A - Set title for the current window. This is usually displayed in the title bar of your terminal window on your local machine. Helpful for keeping track of logins and tasks.
  • "Ctrl-a" k - Kill current window. I prefer to use the Linux "exit" command to end my sessions but if you need to rid yourself of a terminal you can Kill it.

This is only a partial listing of commands. Screen is very powerful, check out the complete documentation here or access the online help via "Ctrl-a" ?.

Resuming Screen Sessions

The real power of Screen is the ability to resume sessions. If you only have one suspended session simply issue this command to resume it:
screen -r
If you have multiple sessions available they will be displayed
[oracle@mymachine1 ~]$ screen -r
There are several suitable screens on:
        6809.mytask     (Attached)
        26514.david      (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.
[oracle@mymachine1 ~]$ 
If the screen session is listed as Detached then you can resume it directly
screen -r 26514
If the screen is listed as Attached then you must detach/reattach it to gain access.
screen -d -r 6809

Terminating your screen session

When you exit your final screen session your screen session will be closed and the following will be displayed:
[screen is terminating]
[oracle@mymachine1 ~]$