oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Unix Gems for Mac OS X

by Kevin O'Malley

I'll bet that just about everyone reading this article has heard of Eric Clapton, The Who, and Bonnie Raitt. I would also guess that many of you know who BB King and Muddy Waters are. But, I would wager that not many have heard of Charlie Patton, Mississippi John Hurt, Reverend Gary Davis, or Blind Blake.

If you've never heard of these blues players, stop now, go to the Apple Music Store and listen to some of their preview tracks. If you like blues, I'm sure you'll enjoy these musicians and will be able to detect how their style has influenced modern players.

What does this have to do with your Mac? Well, it's not just my way of imposing musical tastes on others, or exposing these great players to as many people as possible -- well, sort of. But more importantly, it's this: in any domain, there are hidden gems that never reach our radar screens. In music we have examples such as Don Carlo Gesualdo and Jean-Joseph Cassanéa de Mondonville. In computing, there are many as well.

In this article I'll expose you to some truly useful programs that you may not know about. Then I'll show you how to incorporate them into your daily work.

So put on some of Mississippi John Hurt's music and let's get started!

GNU Screen -- Screen Manager with VT100/ANSI Terminal Emulation

Installation: Comes with Mac OS X

Imagine you use a laptop with little screen real estate. Wouldn't it be nice if you could overlay several shells within a single Terminal window, and access each individually? Or maybe you're running a process on your machine at work and would like to log in from home and check its progress. What about developing code at work, or maybe writing some papers, and being able to get back to the exact place you left off from any other computer -- all with one command?

If any of these things appeal to you, then GNU Screen is for you.

GNU Screen is an application, or window manager, that enables you to interact with many processes through a single terminal window. Basically, you create a new virtual terminal for each process, or session you wish to run. Each of these virtual terminals is layered in a single window so you only see one at a time. You use various screen commands to switch between windows. Screen handles the details of multiplexing the physical terminals between processes.

What does this give you? You now have a single terminal window that holds as many virtual sessions as you like. Screen enables you to easily switch between sessions without opening up lots of shells and cluttering your desktop.

If this is all you used screen for, you'd be missing its real power. The real strength of screen is you can setup virtual sessions on one machine and access them from any other machine. This enables you to work on one machine and continue working from anywhere else, without the hassle of reconstructing each session.

Sound interesting? Let's take a look at screen's basic commands and some examples.

Using Screen

Screen comes standard with your Mac OS X installation so you won't need to install anything new to use it.

To get a flavor for how screen works, let's use a simple example. Imagine each morning when you get to work, you run the same programs -- say emacs for coding, pine for mail, lynx for text-based web surfing, and slrn for news reading. You set this up using screen. (Note: you can install these programs using Fink if necessary.)

First, open a new shell from the Terminal application and type "screen" at the prompt.

% screen

When screen starts, it reads its default initialization information from the file $HOME/.screenrc. This file can contain options, key binding functions, as well as other commands that you use to customize screen to your tastes. Later in the article, I'll discuss some possible customizations you can add to .screenrc. For now, let's just stay with the defaults.

When you run screen, it displays an informational screen. Simply press Space or Return and you are returned to a the prompt. (You can also turn this off by adding the command startup_message off to your .screenrc file.) At this point, you may think that screen did not run -- not so. Screen is lurking in the background available to you at any point.

Now, let's create a new virtual window for each program. To accomplish this, type Ctrl-a c (hold down the control key and press 'a', release the control key and press the 'c' key). You'll see a new, clean window with a new prompt. At the prompt, type the program you wish to run. Repeat this for each program.

  Window 1. Emacs: type Ctrl-a c, at the prompt type emacs 
  Window 2. pine: type Ctrl-a c, at the prompt type pine 
  Window 3. lynx: type Ctrl-a c, at the prompt type lynx 
  Window 4. slrn: type Ctrl-a c, at the prompt type slrn

You should have five screen windows -- the original window and four more running different processes.

Pages: 1, 2, 3, 4

Next Pagearrow