Tuesday, October 30, 2007

View compressed log files easily

Any linux distribution around these days will have compression and rotation in place for files in /var/log (or wherever else they happen to go). So if you look in there, you will see one or two log files (current and the last one) for each process logged, as well as 3-7 compressed files for the same process. These then get rotated out.

In any case, say you want to look inside one of those compressed log files. You could write out an untar command and then view the file. Then have to delete the temporary file. Messy. There is a better way.

The first I found was interesting (from PuppyLinux): Simply run man ./COMPRESSEDFILE. You view the contents of the file with the man file viewer. The annoying thing is that is does funny things with line breaks.

A much better way: zcat COMPRESSEDFILE | less. You view the file in less, and when done, there is no temp file to delete. To make it faster, just add a simple alias: alias viewlog="zcat $1 | less". This makes viewing those compressed logfiles as painless as viewing the current ones.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home