This site is now 100% read-only, and retired.

An introduction to the visual features of GNU Screen

Posted by Steve on Mon 5 Nov 2007 at 10:11

Many people here use GNU Screen, and I've not seen extensive coverage of the things you can do with the status-line in the past, so I thought a brief overview of a couple of visual settings wouldn't be amiss. Read on for more details.

GNU screen, which we've previously introduced, is a small utility which may be used to leave sessions running when you've logged out, or run multiple console applications in only one terminal. There are many things you can do with it which we'll not cover here, instead we'll look at the status bar.

There are two types of status-bar you may have within a GNU Screen session:

  • A "caption" line.
  • A "hardstatus" line.

Whats the difference between them? Well the hardstatus line is used for status messages from screen - for example to alert you to activity, or other similar messages. The caption line is usually only shown if there is more than one window open, and allows you to view details of them.

As an example add this to your ~/.screenrc file:

caption string "%w"
hardstatus alwayslastline "This is a test..."

This will give your screen sessions two lines at the bottom of the screen - the first showing the open windows, the second showing a static message.

But what if you don't want to have those messages on the screen at all times? Well that's not a problem:

#  Toggle 'fullscreen' or not.
bind f eval "caption splitonly" "hardstatus ignore"
bind F eval "caption always"    "hardstatus alwayslastline"

With these lines in place "Ctrl-a f" will remove them, and "Ctrl-a F" will restore them.

The next neat thing to do is show the output of commands in one of the two lines, here we'll use the hardstatus area to show the output of uptime. There are two things you need to do for this to work:

  • Define a command to run, with a refresh period.
  • Allocate a space on the relevant line to display it

We'll do this as follows:

backtick 1 5 5 uptime
hardstatus alwayslastline "%1`"

Here we've defined a command with ID 1, which is valid for 5 seconds and should auto-refresh after 5 seconds. The command is uptime.

Additionally we've included %1` in format string for the relevant part of the display. This will be substituted with the output of the first command.

The important thing to notice is that the command we've chosen only outputs a single line of text - that must always be the case.

To complete our discussion of this area of GNU screen we should now mention some of the other facilities which are available to users who wish to customize their status bars.

The key to all customization is the use of format strings, strings which you'll enter in the display lines which will be replaced upon display. For example the following lines have extensive format strings:

# look and feel for the bottom two lines.
caption     always        "%{+b rk}%H%{gk} |%c %{yk}%d.%m.%Y | %72=Load: %l %{wk}"
hardstatus alwayslastline "%?%{yk}%-Lw%?%{wb}%n*%f %t%?(%u)%?%?%{yk}%+Lw%?"

Below is a brief summery of the options, copied almost entirely from "man screen". The escape character is '%' with one exception: inside a window's hardstatus line '^%' is used instead.

       %      the escape character itself

       a      either 'am' or 'pm'

       A      either 'AM' or 'PM'

       c      current time HH:MM in 24h format

       C      current time HH:MM in 12h format

       d      day number

       D      weekday name

       f      flags of the window

       F      sets %? to true if the window has the focus

       h      hardstatus of the window

       H      hostname of the system

       l      current load of the system

       m      month number

       M      month name

       n      window number

       s      seconds

       t      window title

       u      all other users on this window

       w      all window numbers and names. With '-'  quailifier:  up  to  the
              current  window;  with  '+'  qualifier: starting with the window

       W      all window numbers and names except the current one

       y      last two digits of the year number

       Y      full year number

With that list there is plenty of scope for creating simple updates to the display. For example displaying the current date, time, and system load would be as simple as:

hardstatus alwayslastline "Host: %H Date: %D-%M-%Y: Load: %l "

If you'd like to experiment yourself there are many more format strings giving a lot of choice for customization (such as the use of colours). To see the full list run "man screen" and search for the section entitled STRING ESCAPES.



Re: An introduction to the visual features of GNU Screen
Posted by ddouthitt (216.165.xx.xx) on Mon 5 Nov 2007 at 17:29
There is now a book about GNU Screen which attempts to detail all of its features without being obtuse or hard to use. The book GNU Screen: A Comprehensive Introduction can be had at .

[ Parent ]

Re: An introduction to the visual features of GNU Screen
Posted by ajt (85.211.xx.xx) on Mon 5 Nov 2007 at 20:42
[ View Weblogs ]

Cool. I have the following lines or something similar. I've no idea where I found them but they seems to work well enough for me.

hardstatus alwayslastline
hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %d/%m %C%a "
caption always "%3n %t%? @%u%?%? [%h]%?"

"It's Not Magic, It's Work"

[ Parent ]

Using the xterm title
Posted by TRS-80 (124.169.xx.xx) on Fri 9 Nov 2007 at 19:33
I have the following in my .screenrc:
hardstatus off
hardstatus string (%n.%t)
termcapinfo xterm*|rxvt*|kterm*|Eterm* 'hs:ts=\E]0;:fs=\007:ds=\E]0;\007'
hardstatus off tells screen not to use the hardstatus line for messages, instead they'll be overlaid in reverse video at the bottom of the screen. The hardstatus string is fairly simple compared to other examples above. The real magic is the termcapinfo line, which makes screen put the hardstatus information in the title of the xterm it's in. PuTTY also supports these escapes.

[ Parent ]

Re: Using the xterm title
Posted by Anonymous (86.65.xx.xx) on Thu 12 Nov 2009 at 13:48
But if you have a screen in screen, would you then see it ?
I find the toggling statusbar safer.

[ Parent ]

Re: An introduction to the visual features of GNU Screen
Posted by spwhitton (77.102.xx.xx) on Thu 8 Apr 2010 at 13:46
I have a complex hardstatus and having it pop up in my terminal emulator's title bar when I hide it using your C-a f shortcut is annoying - and when I use C-a F to get it back, screen messes up and my window manager puts "broken" in the window title. Both of these are worse than the title I have set before either of these shortcuts have been applied.

To fix this behaviour I replaced the bindings with:
bind f eval "hardstatus alwaysignore"
bind F eval "hardstatus alwayslastline"

and now they don't touch my terminal emulator's window title. Not sure yet if there are any unfortunate side effects.

[ Parent ]