tail -f findings.out

« Loops in the CLI: Warm and Fuzzy

Reference script for CLI color codes »

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.

Share and Enjoy:
  • email
  • LinkedIn
  • Slashdot
  • StumbleUpon
  • Technorati
  • Netvibes

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

Possibly Related (no promises):

  1. Useful ways to list directory contents

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

Tags: , , ,
October 30, 2007 - 3:20 PM
2 comments »
  • megacd

    January 28, 2009 | 11:13 AM

    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).

  • Samuel Huckins

    January 28, 2009 | 11:15 AM

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

Leave a reply

Subscribe without commenting

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.