Wednesday, November 7, 2007
2:29 PM

Tail multiple files


In an earlier post, I discussed 2 commands for continuously displaying the contents of a file: tail -f and less. I mentioned that with less, you can scroll back, perform searches, and, in general, use all the interactive commands that come with less.

There is (at least) one scenario where tail -f is more appropriate than less:
when you need to tail more than 1 file.
$ tail -f /var/log/messages    /var/log/mail.log
==> /var/log/messages <==
Nov 6 20:17:54 tiger -- MARK --
Nov 6 20:38:04 tiger -- MARK --

==> /var/log/mail.log <==
Nov 5 18:04:51 tiger sendmail[3090]: gethostbyaddr(192.168.0.102) failed: 3
Nov 5 18:04:52 tiger sendmail[3192]: gethostbyaddr(192.168.0.102) failed: 3
Nov 5 18:05:07 tiger sm-mta[3733]: starting daemon (8.13.8): SMTP+queueing@00:1 0:00
Nov 5 18:05:07 tiger sm-mta[3733]: restarting /usr/sbin/sendmail-mta due to sig nal

==> /var/log/messages <==
Nov 6 20:58:05 tiger -- MARK --


The contents of each file are interspersed throughout the output, making it somewhat hard to read.

Alternatively, you can use another tool named multitail to tail multiple files. Multitail divides the console into multiple windows: one for each file.
multitail  /var/log/messages  /var/log/mail.log



To scroll back, type b. Then, select the file to scroll. The selected file will be displayed in a new window. Now, you can use the arrow keys as well as the PageUp/PageDown keys to scroll. To exit the scroll window, type x.

I find multitail a bit clumsy to use. For simple log file viewing I tend to stick with tail -f.

Note that multitail may not be installed by default in your Linux distribution.

StumbleUpon Toolbar

0 comments:

Post a Comment