Friday, May 11, 2012

gzip and the stdout

As a native Windows user, I still don't consistently think in a CLI mindset. So when I finally came across a shortcut to a common annoyance, it was a forehead slap of "Oh, THAT'S why that's there."

When writing apps hopefully, like me, you roll over your logs and compress them to conserve space. However, also like me, you have to check those files in a production or production-like environment. Which means either logging in as some super-user, or downloading the files, or copying them to some /tmp directory, when you can unzip the files, and read them.

Or you could save yourself a couple of unnecessary steps and just think in CLI using the "-c" flag for gzip, then pipe the output to less, more, or wherever.

bash> gzip -cd rolledover.20120510.log.gz | less

3 comments:

  1. This may seem silly, and a little "newb", but it's surprising how few of my coworkers knew how to use "stdout". So I figured it'd be good to keep it handy for reference.

    ReplyDelete
  2. If you want to save yourself a few characters you can use zcat (or gzcat on some systems). It's typically an alias for gunzip -c e.g:
    zcat rolledover.20120510.log.gz | less

    ReplyDelete
  3. Well Doug, now you're just getting lazy. ;-)

    ReplyDelete