Viewing a .gz file directly using Less

one way to view a file in Linux is via Less, but what if you want to less a .gz file?

one way to do it is to extract the gz file then execute a Less on the extracted file,

however another method i would like to share is the LESSOPEN env variable.

Less will auto detect if the environment variable is present then uses it.

try executing in your command line.

export LESSOPEN="|gzip -cdfq %s"

then less a .gz file.

You wounldnt want to exec the export again again, you may automate this by including this in your bash profile

Enjoy the power of LESSOPEN!

1 Comment

  1. Chris
    January 21, 2015

    zless and zcat area your friends, they are the equivalent of less and cat, only for gzipped files 🙂

    Reply

Leave a Reply

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