Using the "screen" Command

The Linux screen command is used to manage and switch between a collection of distinct terminal sessions. You can detach from and re-attach to an individual terminal/"command line" session. This is especially useful if a process or computation needs to continue even though the user must log off of a computer to attend to other matters.  Screen will also let the user re-attach to any active session the user owns on the host machine (for example, one can disconnect at work and re-attach from any other SSH capable machine, such as a home desktop computer).

Launching Screen

To initially evoke screen, simply type the name a command line:

screen

This will fill the users's terminal display with a message similar to the following:

Screen version 4.00.03 (FAU) 23-Oct-06
Copyright (c) 1993-2002 Juergen Weigert, Michael Schroeder
Copyright (c) 1987 Oliver Laumann
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program (see the file COPYING); if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Send bugreports, fixes, enhancements, t-shirts, money, beer & pizza to
screen@uni-erlangen.de
[Press Space or Return to end.]

As instructed, press space or return. This will create a new terminal session, but be aware that you're now in a screen container. Should you type exit, screen will terminate and return you to your previous single session standard Linux command line:

exit
[screen is terminating]
thales:~>

Using Screen

Once screen is started, you are in a terminal session which can be controlled by screen command (These are initiated using the control key so any shell command containing control must be treated in a special way. See the man page for screen by typing man screen) . In fact, you can run multiple terminal sessions at the same time in screen and shift between them. For example, perhaps you've started screen and begin using Mathematica. A new terminal session can be started by pressing the control key and A at the same time, then the letter C.

ctrl-a 
c

You can switch back and forth between these two screen terminal sessions in a similar manner. The following will take you out of your current screen, "Screen 1", and back to your Mathematica program, which is running in "Screen 0":

ctrl-a
0

You can go back to "Screen 1" by typing:

ctrl-a
1

If we type exit in "Screen 1", that screen will close and we'll only have "Screen 0" left. If you have 7 screen sessions active and exit "Screen 4", all other screens retain their numbering and the 4th slot will be unused until the next screen is created (meaning a new screen becomes "Screen 4" rather than "Screen 8" to fill the hole).

 

Hint for displaying current terminal sessions in a screen container:

Enter a nonexistent screen number to see the current active sessions displayed at the bottom of the screen. 

Detaching and Re-attaching to a Screen Session

To disconnect from Screen while it remains active:

ctrl-a
d
[detached]

Let's say you logged off after detaching and log back in a day later. Type the following to re-connect to your screen session:

screen -r

But what happens if you leave yourself connected in your office, but want to use your screen session at home after SSHing into the computer? No problem. The following command will hijack your active screen session and disconnect it in the office:

screen -dr

If you don't want to actually detach the office session, but only mirror the screen session in two places, as weird as that may be:

screen -x

Please be considerate of other users on shared machines and terminate your screen sessions when no longer needed.

When work is completed, either detach for further use or exit all screens to exit screen. NOTE: Should a server need to be rebooted, all active screen sessions are discarded. Always save your data periodically and quit programs when they aren't needed.