Tuesday Tiny Techie Tip

less(1) is more(1) only more so

No, this isn't about the voluntary simplicity movement.

Most everyone is familiar with more(1), the gadget that lets you look at voluminous output a page at a time. more is pretty limited though, in that you can only move forward and back by line or screen, and there's no support for searching.

Enter less(1). less is a once public domain, now GNU replacement for more. The original version appeared in the old net.sources pre-Usenet group way back in 1985.

By default, less works just like more. You give it the name of a file to look at, or pipe a command's output to it, and it displays one screen's worth of the stuff and waits for you to hit the spacebar before showing the next screen:

% less .login
% ypcat -k aliases | less

The most noticable difference is that less doesn't automatically quit when it reaches the end of a file unlike more. When you reach the end of the file (or pipe), type "q" to quit. You can override this behavior by putting the "-e" option in the LESS environment variable:
% setenv LESS -e

Once inside of less, you can move up and down in the file using either vi(1) or emacs(1) motion controls. You can search for a string using the standard vi method of /pattern to search forward for pattern or ?pattern to search backwards. "n" finds the next match in the same direction, "N" in the opposite direction. Search matches are highlighted by default.

less has lots of other gewgaws and doodads for doing fancy stuff. Consult the man page for details, or read the online help by typing "h" inside less.

If you decide you like less and want to use it as your default pager instead of more, set the PAGER environment variable to less:

% setenv PAGER less

Then things like man(1) will use less instead of more.

Tuesday Tiny Techie Tip -- 25 March 1997
Forward to (04/01/97)
Back to (03/18/97)
Written by Jeff Youngstrom

Up to the TTTT index

Tuesday Tiny Techie Tips are all © Copyright 1996-1997 by Jeff Youngstrom. Please ask permission before reproducing any of this material.