-->

Previous | Table of Contents | Next

Page 59

the spacebar, and you can go backward one screenful by tapping the B key.

The more command also has a number of command-line options. You can customize the screen prompt (more displays the current percentage of the file you're reading), set the screen size (the number of lines shown when going forward or backward through your file), use multiple filenames or wildcards, and turn scrolling on or off, in addition to other options.

Although you may find the more command to be more than adequate in reading files, you might really like the less pager.

Browsing Files with the less Command

You'll find that less is more or less like more, but you'll also discover that less is much more than more. Confused? Don't be, because less, like more, is also a pager command. But its author, Mark Nudelman, has improved on a number of features in the more command, and added many others.

The less command offers a number of advantages over more:

You'll find that after you install Linux, the less pager is the default pager used by a number of programs, such as the man command. And if you need to read compressed files (those with a .gz extension, and about which you'll learn in Hour 5, "Manipulation and Searching Commands"), you can use the zless command, found under the /usr/bin directory.

Reading the Beginning or End of Files with the head and tail Commands

Although the head and tail commands are not pagers per se, they can make life a lot easier when all you want to do is read the beginning or end of a file. These programs, like most

Page 60

Linux commands, are designed to do one or two things, but they do these tasks well.

The head command has a number of options besides the traditional -n, which prints the first n lines of a file. You'll find that the head command in your Linux distribution, which is part of the GNU text utilities, will also print any number of 512-character, 1-kilobyte (1024 bytes), or megabyte-sized blocks from the beginning of a file. Like the cat command, head can also handle binary files.

If you use head in the traditional way, you strip off lines from the beginning of one or several files. For example, if you'd like to do a quick check of the formatting of all the manual pages for programs with names beginning with "xm" under the /usr/man/man1 directory, you can use the following command:


# head -5 /usr/man/man1/xm*.1

==> /usr/man/man1/xmpeg.1 <==

.TH XMPEG 1 "6 FEBRUARY 1993" "X Version 11"

.SH NAME

xmpeg - X11 MPEG-Player [Version 1.0]

.SH SYNOPSIS

.B xmpeg



==> /usr/man/man1/xmplay.1 <==

.TH XMPLAY 1 "6 FEBRUARY 1993" "X Version 11"

.SH NAME

xmplay - X11 directory browser for xmpeg [Version 1.0]

.SH SYNOPSIS

.B xmplay

Note that the default output from the head command is to include the filename. If you'd prefer just to have the information, use the -q option, for example:


# head -5 -q /usr/man/man1/xm*.1

.TH XMPEG 1 "6 FEBRUARY 1993" "X Version 11"

.SH NAME

xmpeg - X11 MPEG-Player [Version 1.0]

.SH SYNOPSIS

.B xmpeg

.TH XMPLAY 1 "6 FEBRUARY 1993" "X Version 11"

.SH NAME

xmplay - X11 directory browser for xmpeg [Version 1.0]

.SH SYNOPSIS

.B xmplay

The tail command is especially useful when you're faced with the task of reading through large files where the most useful information is at the end of the file. One example task is if you want to look at the system messages for errors. One message file, located in /var/log, contains details of system operations, but the log is updated at the end of the message file (in other words, text is appended, so the most recent messages are at the end of the file). To look at the last 12 lines in the message file using tail, make sure you're logged in as root, and type

Page 61


# tail -12 /var/log/messages

Nov 12 21:02:02 localhost cardmgr[152]: initializing socket 0

Nov 12 21:02:02 localhost cardmgr[152]: socket 0: ATA/IDE Fixed Disk Card

Nov 12 21:02:02 localhost cardmgr[152]: executing: `insmod /lib/modules/2.0.30/p

cmcia/fixed_cs.o'

Nov 12 21:02:03 localhost kernel: hdc: SunDisk SDCFB-4, 3MB w/1kB Cache, LBA, CH

S=123/2/32

Nov 12 21:02:03 localhost kernel: ide1 at 0x100-0x107,0x10e on irq 3

Nov 12 21:02:03 localhost kernel:  hdc: hdc1

Nov 12 21:02:03 localhost cardmgr[152]: executing: `./fixed start hdc'

Nov 12 21:02:03 localhost cardmgr[152]: initializing socket 1

Nov 12 21:02:03 localhost cardmgr[152]: socket 1: Serial or Modem Card

Nov 12 21:02:03 localhost kernel: tty01 at 0x02f8 (irq = 5) is a 16550A

Nov 12 21:02:03 localhost cardmgr[152]: executing: `insmod /lib/modules/2.0.30/p

cmcia/serial_cs.o'

Nov 12 21:30:17 localhost PAM_pwdb[556]: (su) session opened for user root by bball(uid=0)

Being able to read large files in this way is convenient, considering that the system messages can grow to more than a million characters.

Page 62

Previous | Table of Contents | Next