The Screen program provides efficient methods for opening and maintaining multiple terminal sessions through which you perform all your text-based tasks. It is typically used to run shell windows to remote servers, for example from you local workstation. Screen works well in combination with powerful text editors such as Emacs or VI.
In most cases screen should already be installed and you should be able to start it up by typing the following at the command prompt:
After you start up screen it will show a shell window that may look just like the one from which screen was started. However, you have now the option run multiple terminal (shell) windows concurrently, and you have available all the other useful functions that screen provides, such as logging and session management.
Perhaps one of the most useful features is that you can re-connect to your sessions after you log out, move to another computer, or get disconnected, and continue working as if nothing happened. All your edit sessions, shell windows, etc. will be there just as you left them.
In order to re-connect to a previous screen session you use the "-r" flag like this:
screen -D -r
All screen commands start the "Ctrl-a" key-stroke. To create a new screen (window) use "Ctrl-a c". To switch to a particular screen (window) just specify the screen number. For example, "Ctrl-a 2" will switch to screen 2. To see the list of predefined key bindings, use "Ctrl-a ?". To issue commands other than those available through key-bindings, you use the "colon" short-cut: "Ctrl-a :" followed by the screen command.
You can use the screen initialization file ".screenrc" in your home directory to define the start-up configuration for your screen sessions. You can put a sequence of screen commands in this .screenrc file, which will be applied by default to any new screen session. The following example illustrates the format of a .screenrc file:
# Start windows
screen -t monitor 0 top
screen -t emacs1 emacs -nw
# Key bindings
bind E screen -t emacs emacs -nw
bind T title project1
The line "screen -t top 0 top" runs the command "top" in window (screen) number 0 and give the window the title "monitor".
The next line starts a window with the text editor "emacs" giving it the title "emacs1". The "-nw" is a parameter for the emacs process telling it not start a new window but use the terminal (shell) window for display. Without this flag, which stands for "no window", emacs may try to start an X-window to display the editing session.
The "bind" command sets or changes key bindings. A useful feature of screen is the ability log sessions, that is, save everything written to a screen window in a file. By default the log files are saved in your home directory and their name starts with "screenlog". You turn logging on and off with the key-stroke:
Ctrl-a : logfile newname