Screen: Tips & Tricks

[ Friday, 13 July 2007, Treadstone ]

In this article I will describe a very useful program: GNU Screen. Usually this program is used by people who have a shell account on a Unix server. But it can be also helpful to people who haven’t yet started to use a terminal or even Linux/Unix at all. Screen — simply — is a program which enables users to create more system shells without the need of logging in multiple times. Moreover it allows to leave programs running after you’ve logged out. What can it be useful for? For example to continue compiling or downloading something when someone wants to use the computer, or to run more than one terminal for one ssh connection. There are many more possible ways of using it…

Author: Łukasz Olender

Throughout the text I will use this C-a for the shortcut of Ctrl+a and C-d for Ctrl+d. I’d like to emphasize that C-a A (Ctrl+a and next A) and C-a a are two different shortcuts :) . I will also refer to the program simply as “Screen”, not GNU Screen, for simplicity reasons.

1. Quick start

To create a new terminal session just enter the command screen. It will grant you the access to, what appears at first look, to be an unchanged shell. But in fact there are many useful features a key sequence away. But let’s start from the begining :)

In the new shell, you can do the same things as in a normal terminal. When you want to shutdown the screen, you press the combination C-d. If you want to leave programs opened in screen running after logout, you have to press C-a d before. Then the text [detached] will appear on the display, what means that screen is running in the background, and you can log out knowing that all your programs are still functioning. When you want to reenter the screen session, type screen -r. You can have more than one screen session, detaching from active ones and creating new ones. But to reattach to any of detached session, you have to know its PID (Process ID), or name. To see running sessions type screen -list. The first column contains the PID of each session. To restore a session type screen -r [PID]. But it is very inconvenient to remember or list these numbers every time you want to reattach. Fortunately you can use the “-S” switch. With its help you can give a name to each session when creating it. To create a session named “wget” you type screen -S wget. This makes it far easier to get back to any session. Just enter screen -r wget and it’s done.

2. Running programs in the background

Sometimes it would be useful to make screen automatically open a program in its session, give it a name and detach returning to a normal shell, in one command. Use the “-md” options to do this. Combining this with the “-S” option gives some interesting effects:

screen -S ekg_session -md /usr/local/bin/ekg &

Screen will create one session, name it “ekg_session”, start the ekg program running inside it and then detach it. Using this method, checking your account on a unix server, you can have either online or “away from the computer” status all the time by one command, while doing other things on the server. Naturally, you can combine many commands into a single command, which makes returning to your work environment easier:

screen -S ekg -md /usr/local/bin/ekg & screen -S mc -md /usr/bin/mc & //
screen -S rtorrent -md /usr/bin/rtorrent &

This makes screen create three differently named sessions in the background with my favourite terminal programs – ekg, mc and rTorrent.

3. Regions and tabs.

Even though running multiple screen sessions is catered to, its creators give you another choice of how to work. You can run multiple shells within one session! What’s more, you can even display these shells in one terminal window.

But so as not to get lost in these windows, I suggest you create tabs similar to those found in web browsers. You can do this by writing to your configuration file ~/.screenrc one of the following codes:

hardstatus alwayslastline      
hardstatus string '%{= mK}%-Lw%{= KW}%50>%n%f* %t%{= mK}
%+Lw%< %{= kG}%-=%D %d %M %Y %c:%s%{-}'


hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}
(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m 
%{W}%c %{g}]'


hardstatus alwayslastline
hardstatus string '%{gk}[ %{G}%H %{g}][%= %{wk}%?%-Lw%?%{=b kR}
(%{W}%n*%f %t%?(%u)%?%{=b kR})%{= kw}%?%+Lw%?%?%= %{g}][%{Y}%l%{g}]
%{=b C}[ %m/%d %c ]%{W}'

With the first code each tab will have a number, a name plus time and date. The second one will give you tabs that will be created in the center and the active tab will be highlighted in red and also have the hostname displayed. The last code will additionally display the processor usage. You can create your own codes but it is a rather specialized task – I refer you to the system manuals for more information.

You already have tabs, now it’s time to create new terminals.

Open a screen session then press C-a c. A new tab is created. But both tabs have the same title. To change the title of the active tab, press C-a A and enter a new name. Creating tabs without a shell but with a program running automatically is a useful feature. The new tab will inherit the name of the program. To use this option press C-a : and enter the following command screen [program name] (this is the way you enter all commands during the screen session). To go to the next tab press C-a n and to return to the previous one press C-a p. To switch between the tabs use C-a ". This will show you a list of all the tabs.


Regions are a very useful feature. They enable opening many programs and shells in one window of screen. To do it just press C-a S. The window will split into two separate areas. There will be your actual shell at the top part of the window and the bottom part will be empty. To switch to the bottom part press C-a [Tab]. You have to create a new shell in the new window, so press C-a c. You can create more regions by pressing C-a S more than once and creating new shells in them. Tabs display the active region shellname in its titlebar. You can also switch between tabs being in a region, so e.g: you have 4 tabs and 2 regions. Each region can display one of these tabs. A nice trick is that many regions can display the same tab and they will react simultaneously. It is difficult to describe but is very helpful when you work in multiuser mod and you want to see what another person is doing. You can change the size of each region by entering resize [size], where size is the number of lines.

Two windows filling whole the display with screen splitted into two regions
Img. 1 Two windows filling whole the display with screen split into two regions

4. Configuration file

Previously I mentioned about the configuration file. I wrote that it is in a subdirectory in the home directory named ~/.screenrc. But you can have tens of such files, and when you want to use any of them run screen with the option -c [filename]. What these files can be? Simply it can contain any of the commands that you usually enter after pressing C-a :. Below I include one of configuration files which causes splitting a window into two regions and running ekg in the top one.

  • screen ekg — runs ekg
  • title ekg — gives title to the window
  • split — splites window into two regions moving ekg to the top one
  • focus — switches to the bottom region
  • screen — runs default shell, in my case it is bash
  • title bash — sets title to the bottom region
  • focus — switches back to the top one

As you can see, you can automate a lot of actions which you would do after connecting to a server or running a terminal. A full list of commands can be found in the manual.

5. Logging to file.

To log all the data displayed in a screen session or tab into a file, enter the following command:

  • logfile [filename] where filename is the name of the file where all the data will be logged. The default name is screenlog.0 (or 1,2,3… if there are more screen shells).
  • flush [seconds] is used to set delay between each write to the logfile, by default it’s 10 seconds.
  • To start logging enter log on, to stop log off.

6. The password to screen session.

If there is an important program running in a session you can protect it by using a password. To do this enter password. Then you will be prompted to type your password twice.

After that the hashed password will be displayed. Next you have to copy it to the configuration file after the word “password” in the same line. To cancel the password associated with the session just enter password none in the session or delete the line from the configuration file to cancel the password permanently.

7. Screen running right after connecting to a remote host.

In fact this tip has not much in common with screen but still I think it is very useful. If you want to run screen right after connecting to a remote host just enter ssh [username]@[remote host name] -t screen -RD. Unfortunately this command will work only if there is only one screen session running on the remote host. If there is more than one session you have to know its PID or name and use this: ssh [username]@[remote host name] -t screen -R [sessionname/PID]. When you shut down the screen, SSH will automatically log out.

8. Locking the display.

To lock the display use the following command lockscreen or the shortcut C-a x. It doesn’t block the session (like it was in point no. 2), but only “freezes” the display. So detaching and attaching again will cause that you grant the access to session. It can be useful when you are connected to a remote server using the previous tip and you have to go away from the computer. You can’t change the password, because your own user password will be used.


I think these tips will be useful for you. I have been using screen for a long time without knowing about such things as regions, tabs and all features I described here.

Proof-read by trashcat, chaddy

Warning: include_once(/sites/ failed to open stream: No such file or directory in /sites/ on line 48

Warning: include_once(): Failed opening '/sites/' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /sites/ on line 48

Subscribe to RSS feed for this article!


fold this thread mudrii  Friday, 13 July 2007 o godz. 8:00 am #  Add karma Subtract karma  --1

Nice how to
Thnak you very much

(Comments wont nest below this level)
fold this thread mudrii  Friday, 13 July 2007 o godz. 8:15 am #  Add karma Subtract karma  +2

Just a small fix in
to create a new shell in the new window, so press C-a C.
correct is to press C-a c

(Comments wont nest below this level)
fold this thread michuk  Friday, 13 July 2007 o godz. 10:03 am #  Add karma Subtract karma  +0

@mudrii: thanks, fixed.

(Comments wont nest below this level)
fold this thread mudrii  Friday, 13 July 2007 o godz. 11:20 am #  Add karma Subtract karma  +0

is screen support vertical region split ?
I can not find any info

PS: for more detailed info about screen check

(Comments wont nest below this level)
fold this thread attila  Thursday, 4 June 2009 o godz. 9:05 pm #  Add karma Subtract karma  +1

yes, C-a | (pipe)

fold this thread What is Linux?  Saturday, 14 July 2007 o godz. 11:01 am #  Add karma Subtract karma  +0

On Digg it was mentioned that this tutorial is good for those who don’t know the terminal. What can I use it for? With Ubuntu Linux?

(Comments wont nest below this level)
fold this thread michuk  Saturday, 14 July 2007 o godz. 2:14 pm #  Add karma Subtract karma  +0

On Digg it was mentioned that this tutorial is good for those who don’t know the terminal. What can I use it for? With Ubuntu Linux?

On Digg it says: It can be also helpful to people who haven ’t yet started to use a terminal or even Linux/Unix at all.

Screen is used to make use of terminal easier. So — the tutorial may be good for those who haven’t used the terminal before but want an (kind of) easy way to get started. Of course you need to have a need for using a terminal in the first place. If you prefer GUI, screen won’t be very helpful to you anyway.

(Comments wont nest below this level)
fold this thread phil  Saturday, 14 July 2007 o godz. 3:18 pm #  Add karma Subtract karma  +0

screen -x is also your friend. Allows the same screen to be attached multiple times

(Comments wont nest below this level)
fold this thread Troy  Saturday, 14 July 2007 o godz. 5:56 pm #  Add karma Subtract karma  +1

I absolutely love screen. At work I usually have some 4 or 5 named sessions going for different tasks. One thing I did not like initially was all the C-a business. I’m not a control sequence fan (can you guess which unix editor I use? :) ) so it was annoying.

I saw a tip to map it to the backtick character “`”. It’s almost like hitting the “ESC” button like I do in my favorite editor! Of course, if you want to actually TYPE an “`” you have to hit it twice. To set it up add the following to your .screenrc or type it into the screen command-line (which you get to by typing C-a :)

escape “

May favorite part about it is that I can use ` to quickly cycle through all my “tabs”.

You could change it to anything you like so just play around with it.

(Comments wont nest below this level)
fold this thread Mark  Monday, 16 July 2007 o godz. 9:18 am #  Add karma Subtract karma  +0

Thanks michuk for helping me moving my screen experience onto the next level. Great howto.

(Comments wont nest below this level)
fold this thread Pádraig Brady  Monday, 16 July 2007 o godz. 1:07 pm #  Add karma Subtract karma  +0

Thanks for the article. Screen rocks.
Here are my screen tips:

(Comments wont nest below this level)
fold this thread Abdul-Jabar  Monday, 16 July 2007 o godz. 3:57 pm #  Add karma Subtract karma  +0

I got one question about the screen. Scrolling. Is it possible? For example if I start some kind compiling process under the screen with a lot of debbuging information going into STDOUT and deatach at the beginning of the process. After some time attaching to the same screen I would like to see what has happened at the beginning but I can’t because I can’t scroll (actually i don’t know how) to the previous page like sift+PgUp in common bash shell.

(Comments wont nest below this level)
fold this thread Rick  Monday, 16 July 2007 o godz. 4:37 pm #  Add karma Subtract karma  +0

It’s actually easier than a normal terminal session since you don’t have to use the mouse. Simply enter “copy mode” with ctrl-[ and you can then use vi-style key navigation, including the page up/down keys. Marking for copy is as simple as placing the cursor at your start point, hitting space, then moving the cursor to your endpoint and hitting space again. To paste the copied information, use ctrl-].

(Comments wont nest below this level)
fold this thread Super Mike  Monday, 16 July 2007 o godz. 4:39 pm #  Add karma Subtract karma  +0

Do you know the technique for using Screen to share my SSH connection with a mentor in an office? For instance, I might be new at something, so I fire up Screen upon connection. The mentor can then supposedly login on SSH and attach to my session, either sharing keyboard control or monitoring it. We can then chat in another window where he gives me advice on something.

(Comments wont nest below this level)
fold this thread Abdul-Jabar  Monday, 16 July 2007 o godz. 5:47 pm #  Add karma Subtract karma  +0

Thx Rick! And thx to the author for the howtows and thread. But Rick, it looks like Ctrl-a-[ key sequence should be entered to get into copy mode. Isn’t it? Anyway the advice is what i was looking for!!!!

(Comments wont nest below this level)
fold this thread ginger  Monday, 16 July 2007 o godz. 8:36 pm #  Add karma Subtract karma  +0

Screen is excellent! Does anyone know how to change the prompt color (in .screenrc) to something other than the default colors?

the manual says this:
“Colors are coded either as a hexadecimal number or two letters specifying the desired background and foreground color (in that order).”

caption always “%{RW}%t – %n”
shows the caption as bright red text on a bright white background using the two letter combination.

so what if I wanted blue text (hex #0021A5) on an orange background (hex #FF4A00) using hexadecumal numbers as the manual mentions?

(Comments wont nest below this level)
fold this thread Mike  Tuesday, 17 July 2007 o godz. 2:48 am #  Add karma Subtract karma  +0


For changing prompt colors, you want to edit the environment variable ‘PS1′, found in ~/.bashrc for me (Ubuntu 7.04).

Here’s a good primer for tweaking colors in Bash:

(Comments wont nest below this level)
fold this thread kace  Tuesday, 17 July 2007 o godz. 6:44 am #  Add karma Subtract karma  +0

Very nice. … I especially like to use screen in system start-up scripts for programs that need/want a console.

(Comments wont nest below this level)
fold this thread Andrew  Tuesday, 17 July 2007 o godz. 10:57 pm #  Add karma Subtract karma  +0

2Super Mike:
You can try `screen -x`, but in this case you needa set permission up to share the same session between two users.


(Comments wont nest below this level)
fold this thread Daniel  Wednesday, 18 July 2007 o godz. 9:53 am #  Add karma Subtract karma  +0

michuk, this article is very handy.

I am just wondering how you created two-column windows. Usually those windows are overlapped.

“ratpoison” and “quadconsole” can do two-column windows, but “screen” is more convenient.

(Comments wont nest below this level)
fold this thread Mohammad Bahathir Hashim  Wednesday, 18 July 2007 o godz. 10:48 am #  Add karma Subtract karma  +0

GNU Screen is my favorite tool, and cannot live without it.

In latest/CVS version of GNU screen, you able to ‘VERTICAL SPLIT’ (using key ‘C-a |’ (left|right) , too.

(Comments wont nest below this level)
fold this thread Taco Buitenhuis  Wednesday, 18 July 2007 o godz. 12:38 pm #  Add karma Subtract karma  +0

Is it possible to start screen automatically when I log in?

I think adding it to my .bashrc will lead to infinite recursion since screen will launch bash which then will launch screen etc etc.

Making screen my shell won’t work either, because then it will try to start itself.

So how do I avoid having to type “screen” (or “control-r sc” :) ) every time I log in?

By the way, you don’t need to type “control-a :screen somecommand” to run somecommand in a new window, “screen somecommand” from the shell will work too.

(Comments wont nest below this level)
fold this thread blackhole  Wednesday, 18 July 2007 o godz. 1:19 pm #  Add karma Subtract karma  +0

Is it possible to start screen automatically when I log in?

On my system, adding the following two lines at the end of ~/.bash_profile worked:


In any case, if you are worried about infinite recursion, you can always test against $SHLVL. At login it is 1. After starting screen, it will be 2, etc.

(Comments wont nest below this level)
fold this thread SimpleSimon  Friday, 28 September 2007 o godz. 7:38 am #  Add karma Subtract karma  +0

I’ve tried having screen start automatically at login, but it ends up creating a whole bunch of screens.

What is the proper way to configure my system to have screen start automatically (and reconnect to any pre-existing sessions if there are any running) ???

fold this thread AntEater  Friday, 20 July 2007 o godz. 6:12 pm #  Add karma Subtract karma  +0

Another tip I’d like to add is that you can change screen from using C-a for it’s command prefix to C-z. I tend to use emacs most of the time and the C-a key binding conflicts with the editor’s key bindings. You can do this by adding the following to your .screenrc:

escape ^zz

Since C-z is normally used to suspend a process if I forget where I am and use C-z in a non-screen terminal I can easily recover using “fg”.

Cool article. I’ve been using screen for about 5 years and I learned a couple of useful tricks here.

(Comments wont nest below this level)
fold this thread Eduardo Costa Lisboa  Saturday, 21 July 2007 o godz. 3:01 pm #  Add karma Subtract karma  +1

Now it’s about time to talk about copy & paste:

To enter Copy mode:

C-a [
C-a Esc
or even
C-a C-[

Then you can use the direction arrows, as well as pg up/down to navigate accross the pages of a screen. To begin selecting a text, press space, and then go to the end of your selection. Then, press space again.

You will see something like:

Copied 6 characters into buffer.

Now, try changing your window and press:

C-a ]

You will be pasting your buffer directly to the standard input of your other window. Pay attention, as it is very important: Paste pastes into your standard input, not standard output. Thus, it is like you have really typed what you have pasted.

Instead, if you want to paste it to a file, say, a log, or something, just do like this:

C-a >

Screen will create a file under /tmp with a name like screen-exchange containing exactly what you have copied into the buffer.

While yet in Copy mode, you can use it just to search for a pattern. It’s like less and vi:


searches for a pattern from the point you are to the end of the page, while:


searches backwards for a pattern.

(Comments wont nest below this level)
fold this thread bigmomma  Friday, 11 April 2008 o godz. 10:44 pm #  Add karma Subtract karma  +0

How did you get the vertical white bars that divide the different screen windows?

(Comments wont nest below this level)
fold this thread bigmomma  Tuesday, 15 April 2008 o godz. 9:13 am #  Add karma Subtract karma  +0

Figured it out myself..
If you have the same question, here is the answer:

To get the divider bars, do NOT use the vertical split patch which can be found here:

But instead use the CVS snapshot of the current development version of screen. Here is the link:

fold this thread zig  Sunday, 4 January 2009 o godz. 3:48 pm #  Add karma Subtract karma  +0

I tried to install the status line at the bottom of the screen using the “hardstatus” commands, but the status line is solid gray. How do I change the colors so I can see the status line text? Using Debian.

(Comments wont nest below this level)
fold this thread pjman  Tuesday, 24 February 2009 o godz. 6:30 pm #  Add karma Subtract karma  +0

I had a similar problem. You have to make sure “hardstatus string” and everything after is on the same line.

fold this thread Mark  Friday, 29 May 2009 o godz. 1:59 am #  Add karma Subtract karma  +0

od lat pracuję z AIX, dzisiaj zacząłem szukać więcej informacji na temat ‘screen’ do mojego bloga – jak będę gotowy to mój post będzie miał link do twojej strony.

Gratuluje bardzo udanej strony (ja nic nie wiem na temat WEB:-()

Pozdrowienia z Philadelphi, USA


(Comments wont nest below this level)
fold this thread Troyski  Wednesday, 12 May 2010 o godz. 10:08 am #  Add karma Subtract karma  error

Excellent article.

My screen-fu skills are up a level.

(Comments wont nest below this level)
fold this thread scraze  Tuesday, 15 June 2010 o godz. 3:14 am #  Add karma Subtract karma  +0

Thanks a lot for the great tips & tricks – I’ve been using screen for some time, but never really looked into some of its basic features – for example, hardstatus and regions. I feel there’s one thing missing in the description of regions though: how to close a region :].. just created one to try it, and then got stuck with it. Found the command to close it on commenter Pádraig Bradynow’s tips & tricks page (too lazy to man screen ;) : C-a :remove or C-a X.

Furthermore here are two little things I’d like to add that I use all the time:
C-a w to show all tabs & their names (kind of useless when hardstatus is on), and C-a a to switch between the current and last used tab. The latter is useful if you quickly want to switch between two tabs not next to eachother; for example, if you want to switch quickly between tab 2 and 4, do C-a 2 C-a 4 to put them in sequence, and then you can use C-a a).

Thanks again!

(Comments wont nest below this level)
fold this thread ikke  Saturday, 16 October 2010 o godz. 4:03 am #  Add karma Subtract karma  +0

GNU screen is pretty difficult if you use it with Putty.
If you set it to work according to Xterm mode then the mouse is completely disabled.
If you set it to Linux terminal mode then the numeric keypad is completely messed up.

So it’s either a functioning mouse or a functioning keypad.

I don’t think so…
Apparently something different is needed. Any ideas about the correct settings?

(Comments wont nest below this level)
fold this thread get a boyfriend  Saturday, 29 December 2012 o godz. 6:03 pm #  Add karma Subtract karma  +0

Hello there, Can I download your photo and usage that on
my website?

(Comments wont nest below this level)
fold this thread shoe lifts  Thursday, 20 June 2013 o godz. 1:58 pm #  Add karma Subtract karma  +0

Enjoyed every bit of your blog article.Really thank you! Want more.

(Comments wont nest below this level)
fold this thread heel spur pads  Thursday, 20 June 2013 o godz. 9:08 pm #  Add karma Subtract karma  +0

Grеаt аrtіcle, totallу what Ӏ wanted to find.

(Comments wont nest below this level)
Name (required)
E-mail (required - never shown publicly)

Adjust field size: shrink | enlarge)

You can use simple HTML in your comments. Some examples are as follows:
  • A hyperlink: <a href="">GNU/Linux for everyone!</a>,
  • Strong text: <strong>Strong text</strong>,
  • Italic text: <em>italic text</em>,
  • Strike: <strike>strike</strike>,
  • Code: <code>printf("hello world");</code>,
  • Block quote: <blockquote>Block quote</blockquote>

About the Author

Łukasz Olender

New AdTaily ads!

Are you a film buff?

film buffs community, movie recommendations and reviews

RSS: Comments

You can follow the comments to this article through a special channel RSS 2.0 .

Related articles: CLI

 more »

Related articles: HOWTOs

 more »

PolishLinux Top Content

Become our fan on Facebook! on Facebook

Follow PolishLinux on Twitter!

Follow polishlinux on Twitter

Google Ads