1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Discuss in my forum

How to use the GNU/Linux "screen" Terminal Window Manager

Commands, Syntax, and Examples


The GNU/Linux Screen program is probably not as widely known and used as it should be. One reason is probably the non-distinctive name "screen", which makes it difficult to find information about it. However, you found it may be well advised to place a bookmark to this page so can more easy come back for more information once you get going with this handy utility.

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.

If you are working from a machine running Microsoft Windows, you can use the utility PuTTY a ssh (secure shell) connection to a remote Linux server, and then run screen from there.

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:


If it cannot find the command you have to add it to your path or install it.

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 -r 

Sometimes you have to forcible disconnect your screen session from another connection. In that case you add the "-D" flag like this:

screen -D -r 

If you want to explicitly disconnect your screen session without terminating it, for example when you go home and want to shut down your workstation, you use the keyboard short-cut "Ctrl-a d" (for "detach").

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

Any line that starts with a "#" symbol is ignored. You can therefore use it to add comments.

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 H

To change the log file name, you use the command "logfile" as follows:

Ctrl-a : logfile newname

As mentioned above, the "Ctrl-a :" key combination sets up the prompt at which you can enter any screen command. In this case the command is "logfile newname", which changes the name of the log file to "newname".

Screen has a rich set of command line options and key bindings that enable you to manage multiple shell windows and efficiently monitor and capture output.

  1. About.com
  2. Technology
  3. Linux
  4. Linux HowTos
  5. Bash How-To's
  6. The Linux Screen Remote Terminal Window Manager

©2014 About.com. All rights reserved.