Вы находитесь на странице: 1из 1

TAKE COMMAND BEGINNERS

File management

TAIL AND
HEAD HEIKE JURZIK

You use programs like less or more when you want to immediately. You can leave this follow mode at any Although many things
view long files such as logs. But these aren't always the time using [Ctrl-C] and once more scroll through the
best choice. head and tail are two simple tools whose file. While running in "follow mode" less notes this can be readily accom-
names describe just what they do, and they make the with the text: plished using graphical
life of every Linux system administrator easier.
Waiting for data... (interrupt to abort) interfaces like KDE or
The end is near — tail in the status line. GNOME, anyone wish-

This neat little program writes, if it is not told to do ing to exploit their
Head to head!
anything else, the last ten lines of each file to the Linux system properly
screen. If it is displaying the tails of more than one This program outputs – as you might have guessed
file, tail notes for the user what file it is busy with at – the top ten lines of a file on the monitor. The cannot dispense with
the time: ==> file2 <==. options available are similar to those of tail: if there the command line.
If you should want tail to display more or less are several files to be displayed an optical separation
than the last ten lines, you can specify the number in the output occurs. The option -n number is also There are also many
of lines using the option -n number. The parameter available in order to display, say, just the first five other situations where
-q (for quiet) is also useful. It comes into play when lines in each case. head and tail are twins which are
the ends of several files are output and you don't dedicated to the same tasks: only one starts from it is good to know a
want to be told which file end is which. (The para- above and the other from below. little about the com-
meter -v for verbose does precisely the opposite!) If you have a whole series of configuration files
Probably the most frequently used option of tail in the directory /etc and are not sure which one you mand line jungle.
is -f (which stands for follow). The display of files have to make a change in, a rapid:
which change constantly (like the log files
head /etc/*.conf
/var/log/messages or /var/log/maillog) should be
updated; to achieve this you must continuously will list the start of all the configuration files. As these
repeat the program call. This option does precisely files usually start with comments that explain the pur-
that. It constantly examines whether the file has pose of the file, the correct one is quickly found.
grown and displays the latest entries. It is useful, for
root@blue ~ > head -n 3 /etc/w*.conf
example, when root would like to view the connec-
==> /etc/webalizer.conf <==
tion messages of a modem: #
# Sample Webalizer configuration file
root@blue ~ > tail -f /var/log/messages # Copyright 1997-1999 by Bradford L. Barrett U
Jul 27 21:02:22 blue chat[568]: expect (ssword:) (brad<\@>mrunix.net)
....
Jul 27 21:02:22 blue chat[568]: Password: ==> /etc/whoson.conf <==
.... # whosun server and client sample configuratiU
Jul 27 21:02:22 blue chat[568]: -- got it on file
Jul 27 21:02:23 blue pppd[567]: Connect: ppp0U
/dev/modem # Configuration entry is: "client" or "serverU
Jul 27 21:02:24 blue pppd[567]: local IP addU " starting from position
ress xxx.xx.xxx.xxx 1,

Follow the lesser tail ==> /etc/wine.conf <==


;;
The command less also has an operating mode that ;; MS-DOS drives configuration
;;
permits the following of changes in a file. If you
type capital "F" in the current less ("F" here stands head has incidentally – unlike tail – no follow
again for "follow") then less waits for new lines to option as it is rather unusual to allow files to grow
be added to the file being viewed and displays them "upwards"… ■

2 · 2000 LINUX MAGAZINE 105

Вам также может понравиться