Monthly Columns
 

Beep!     Beep!            Is that my Pager?

Copyright © 1998 Chris Coleman


The screen is a blur of  words and letters moving too rapidly to be understood.  Every time a command is repeated, the information seems to scroll faster instead of slowing down.  You look around, searching for an answer.  In desperation, you type in gibberish; hoping that it might help relieve your frustration, if not solve the problem.

When suddenly! from the back corner of the room, you hear...    the Narrators voice?

    "Is there no hope in sight?"
    "Will our valiant BSD user be vanquished?"
    "Have no Fear!  This is a job for a pager!"
           People
           Against
           Green
           Emigrating
           Rhinos
    "Well, maybe that's not what it means..., um?...", the narrator's voice fades off some what uncertainly.

You shake yourself and realize that you have fallen into a somewhat disturbing slumber.  You clean the drool off your keyboard and go to work trying to find out what a pager might be.

A pager is a program that pauses your screen output at the end of a page.  PAGER  is in an environment variable in your shell configuration file that determines which pager is used by default.   Several programs use the value from PAGER.  The only one we are going to look at is man.  There are several other programs that don't use a pager that we will need to add paging services to by hand.

In this article we will learn how to

  • Set the PAGER Environment variable.
  • Read the Manual pages.
  • Stop Speeding Bullets.
We will also use the following tools.
  • cat
  • more
  • less
  • setenv
  • The Pipe Operator '|'
  • echo

Selecting a Pager:

There are two main pagers: more and less.  Each one is pretty much like the other.  Less is reported to have more features than more.  Yet, I have heard that more is a version of less hacked to act like more.  So I guess, that less has more, but more is less.  Either way, when you figure out which one you want, you need to edit your shell configuration file.   I just noticed the existence of "most" in the ports collection, so I know there are still other pagers available.

You can determine which shell you are using by typing:

    echo $SHELL

The default shell on BSD is the C shell, or csh.  I have installed an enhanced C Shell called tcsh.  Most Linux users will be more familiar with the Bourne Again Shell, or bash.  The C shells will use .cshrc as the configuration file, and the Bourne Shells will use .profile as their configuration file.
We are going to assume that our shell is a C shell and edit our .cshrc file using vi.

    vi .cshrc


(VI HELP: Use "j" to move the cursor down to the line that says PAGER and press "w" to move to the beginning of the correct word.  Press "cw" to change the word.  Type the correct word and press "Esc" when you are done.  Then type ":wq" to save and exit.)
The new value of PAGER has now been saved so it will be used each time we login or start a new shell.  However, it hasn't changed our immediate environment.  To change it to less we would type:

    setenv PAGER less

This would take effect immediately.  Now when we read the man pages, it will use the pager we just specified to control the screen output.

Reading the Manual Pages

The BSD manual pages (or manpages as they are often called) describe nearly every user command, administrative command, library call, and file format used on the system, plus some other informative tidbits (like a built-in ASCII table).  Each page includes a summary, lists all the options available with the command, and generally goes into detail about the command and refers you to related pages.

To access the Manual Pages, type in man followed by the command you are interested in learning about.  To learn about more for example, you would type:

    man more
 


A full screen of text will appear detailing the complexities of more.  At this point UNIX decides to be unfriendly.  Down in the left corner of the screen, you will see the word "stdin".  It gives no other explanation, but expects you to decode stdin to mean the Standard Input, or the keyboard.  It's waiting for you to press a key.
But not just any key.  Your keystrokes are fed back to the pager you selected, which will interpret how the screen will be displayed.

Since we are reading the man page on more, we discover that pressing these keys will result in the following:

  • "q" Will quit the current session.
  • "b" Go back to the previous screen.
  • "SPACE" Go forward one screen.
  • "j" Go forward one line.
  • "k" Go back one line.

Stopping Speeding Bullets.

You can add a pager to the output of any program that displays to the standard output (your current screen or window).  This is accomplished by piping the output of your program through your pager of choice using the '|' (pipe) operator.  The pipe operator feeds the output of one program to the input of another program. This way commands such as cat, ls, dmesg,  and last  (that normally run at sub light speeds) can be slowed down.  And its easy, just append '|' and the pager to any command that needs it.  For example:

    dmesg | more

This will re-display the your server boot up messages.
 


Or try:

    cat /var/log/messages | more

I can't think of any reason to actually use cat in this instance, since more would do a better job by itself. Try it this way:

    more /var/log/messages

This is quite useful when you want to read a very large text document.

I have only listed the very basic commands for the most common pagers.  There are myriads of command line options and built-in features available, such as searching and command execution.  Most of these are patterned after vi commands.  If you need more information read the man pages on each of the various pagers.

Chris Coleman chrisc@vmunix.com