home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 25.2 Four Ways to Skin a cat Chapter 25
Showing What's in a File
Next: 25.4 The "less" Pager: More than "more"
 

25.3 Using more to Page Through Files

The more utility is light-years ahead of cat ( 25.2 ) . It lets you read files one page at a time. If you had only cat and wanted to read long files, you'd have to read very fast or have a quick trigger finger (on CTRL-s ( 41.2 ) ) to stop the text - or get used to reading the last few lines of a file, and no more. In fact, even the most backward versions of more are infinitely preferable to cat for reading a file - so much so that I don't understand why anyone uses cat for this purpose. [I cat tiny files because I have more and less ( 25.4 ) set up to clear my screen (with the -c option) before displaying a file. -TC  ]

When you start more , it displays the first screen of the file. To move to the next page, press the space bar. You can continue to move forward through the file by pressing the space bar or by pressing RETURN (which moves you forward one line). More recent versions of more allow you to "back up" to previous pages in the file by typing b .

Some other features:

  • If you list several files on the command line, you can type :n to move to the next file and :p to move to the previous one.

  • You can get a "help" screen at any time by typing h .

  • You can jump from more into the vi editor by typing v .

  • You can search for a string by typing / , followed by the string you want. The search string can be a full regular expression ( 26.1 ) . You can find the next occurrence of a string by typing n .

If you invoke more with two or more files, it will display a short header at the beginning of each file. This little nicety is strangely useful. Let's say you want to print all of your .h files with a single command, and you'd like some kind of label before each file. You can use more to create the labels ( 43.10 ) for you:



pr
 
lpr
 

% 

more *.h | pr | lpr

(When more isn't writing to a terminal, it doesn't expect you to type anything; it dumps all files to standard output.)

more has a few defects:

  • Even the best versions can't back up while reading a pipe. So if you pipe the output from some command into more , b won't work.

  • When you get to the end of the last file, more quits. I guess there's nothing wrong with this behavior, but I don't like it; I'd rather have the chance to back up or move to an earlier file.

  • Some implementations of more (System V) terminate if you search for a string that it can't find.

A program called less ( 25.4 ) less utility solves all of these problems.

[Some versions of System V support a somewhat equivalent program called pg instead of more . And some people like to look at files with a read-only version of vi called view . I prefer more or less . :-) - TOR  ]

- ML


Previous: 25.2 Four Ways to Skin a cat UNIX Power Tools Next: 25.4 The "less" Pager: More than "more"
25.2 Four Ways to Skin a cat Book Index 25.4 The "less" Pager: More than "more"

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System