View compressed log files easily

Any linux distribution around these days will have compression and rotation in place for files in

1
/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

1
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:

1
<a href="http://www.mkssoftware.com/docs/man1/zcat.1.asp">zcat</a> 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:

1
alias viewlog="zcat $1 | less"

. This makes viewing those compressed logfiles as painless as viewing the current ones.

Post to Twitter Post to Delicious Post to Digg Post to Reddit

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

This entry was posted in CLI and tagged , , , . Bookmark the permalink.

2 Responses to View compressed log files easily

  1. megacd says:

    Hello,

    zcat | less can be replaced by zless. Some commands can work directly with compressed files :
    zcat
    zless
    zgrep
    zegrep
    zdiff
    zmore

    For zgrep and zegrep, no need to do zcat my_file.gz | grep, do directly zgrep my_file.gz (the same thing with cat | grep and grep directly).

  2. Those are totally awesome! I had no idea. That makes a lot of tasks easier. Thanks for sharing!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>