GNU Screen

GNU Screen is a full screen window manager and is typically bundled within many Unix/Linux based distributions. This includes OS’s like MacOS X and Ubuntu. For the ones it is not bundled in — it can be obtained and installed — it is worth obtaining.

So what is a window manager? Well, just like you have multiple tabs in a browser you can have the same functionality for terminals. Like with most things that you do with just a terminal there is a learning curve associated with it, since there isn’t many visual cues when you first execute it.

This tool was introduced by a co-worker when we were having a difficult time doing remote installations because network communications were not always reliable. If we were in the middle of a long running process and the network dropped then the process being executed could end abruptly. Of course we could kick the process off in the background, but that wasn’t always an option. We had other problems like shell environment variables needing to be reset, etc. Screen is the answer to this problem because even if network connection was lost or you accidentally closed the terminal, you can just reattach to your screen session.

After using this for a couple months, I realized the true power of it. No longer do I need to login to multiple terminal sessions to the same system for multi-tasking activities. Why? You just launch Screen and then add new windows/sessions to the Screen instance. Better yet, you can setup .screenrc to add the windows you typically use, add a title to them and even execute startup commands so that everything is all setup with one simple command.

I searched quite a bit for other articles on the web for how others setup their .screenrc. At the end of the day I have a mix and match of what I found and here it is.
~/.screenrc

# Don't display the copyright page startup_message off
# keep scrollback n lines defscrollback 10000
# default screens
screen -t top 0 top
screen -t main 1
screen -t alt 2
screen -t trenton 3 ssh trenton

shelltitle "$ |bash"

# THIS IS THE PRETTY BIT # change the hardstatus settings to give an window list at the bottom of the
# screen, with the time and date and with the current window highlighted
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}]'

Here are a list of tips or commands I use most frequently:
How to switch between windows? CTRL-a then the number of the screen. For example, if you were using the .screenrc above, the following key sequence would get you to the “main” window.

CTRL-a 2

How to exit screen? There are a couple ways. The annoying way is to type exit out of each window. That can be pretty annoying. Well, you can do a CTRL-d in each one, but that is scary. The easiest way is the use CTRL-a :quit

CTRL-a :quit

The latest rendition of GNU Screen is called tmux.  I haven’t used it as much as Screen, but has good features and is worth looking into if you had to chose between the two.

You may also like...

Leave a Reply