Screen is a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells).
Screen is one of the most frequently used commands while working on remote systems. Since the comfort of having multiple tabs in gnome-terminal or konsole is not possible while accessing a box through SSH, the window management and multiplexing ability of screen is a big relief.
user@box ~$ screen
This will create the initial window and provide you with a shell. From now on you can open separate windows for each of the tasks that you intend to perform. Let us assume that want to use Emacs and IRSSI on two different windows.
user@box ~$ screen emacs -nw user@box ~$ screen irssi
You would need to switch to the window having the shell after each of the above commands. To switch from one window to the other you can use: 'ctrl+a n' or 'ctrl+a p'. The windows will be closed when you close Emacs and IRSSI respectively.
Now that you have opened a few windows you can see a list of the currently opened windows using: 'ctrl+a "'. That is 'ctrl+a' followed by a double-quote character.
One can also leverage this command to submit long tasks to a remote server. eg., if you want to compile a really huge package but do not want to keep your desktop or laptop on for that long, you can start the compilation on a remote server, which will stay up long enough to complete the task and switch off your local machine once the task is initiated. To do this you need to have an account on a server that has the necessary resources and uptime to do your job. Log in to that machine using SSH and use screen as shown below. Let us assume that we want to build GCC 4.1.2 and are now currently in the root of the GCC source directory. For simplicity we consider that we have already run './configure', and now need to run 'make bootstrap' to start the compilation process, which is going to be very lengthy.
user@box gcc-4.1.2$ screen make bootstrap
Once the compilation has started, you can use: 'ctrl+a d' to detach your screen. This will drop you back to the shell which was there before you gave the 'screen' command for the first time. Once you have detached your session, you can safely log out of the remote system and power down your local machine.
Some time later you can log in to the remote machine and check the status of the task you had submitted. To do, this the previously detached session needs to be re-attached.
user@box ~$ screen -r
If the task is not yet finished you will notice that it is continuing in the re-attached window. If it has completed successfully or encoutered an error, you will encounter a message informing you that there is no session left to be re-attached.
In case you are used to using the 'ctrl+a' key for moving the cursor back to the beginning of the line in BASH, Emacs, etc., you will now have to use 'ctrl+a a' instead.
Some of the more common key combinations that you might be interested in are:
C-a ' Prompt for a window name or number to switch to. C-a A Allow the user to enter a name for the current window. C-a c Create a new window with a shell and switch to that window. C-a D D Detach and logout. C-a ? Show key bindings. C-a C-\ Kill all windows and terminate screen.
You can see the manual page for the various options by giving the following commands:
user@box $~ info screen user@box $~ man screen