I am using Ubuntu, and I would like to be able to type less compressed_text_file.gz and page the contents of the text file in uncompressed form. Is there a way to do this?


You can configure the key bindings and set many settings for less in a file called ~/.lesskey. Once you've created the file, run the lesskey command; it generates a file called ~/.less which less reads when it starts.

The setting you want is LESSOPEN. It's an input formatter for less. The less package comes with a sample formatter in /bin/lesspipe; it decompresses gzipped files, shows content listings for many multi-file archive formats, and converts several formatted texts formats to plain text. In your ~/.lesskey:

LESSOPEN=|/bin/lesspipe %s

Use zcat, then pipe it to less.

$ zcat $FILE | less
  • 1
    I would prefer if less just worked on compressed files. – Ryan Thompson May 6 '11 at 18:37
  • 4
    Unlike the accepted answer this one is a clean and unix-way solution. Thanks! – Pavel Vlasov Dec 8 '14 at 11:43
  • This is as simple as it gets, win. One thing to bear in mind is that if you open a large file with less, it opens in a useable way, straight away. With this approach, it will open but you won't be able to do much (if anything) until the compression has finished running it all through the pipe. So if you're planning on opening it repeatedly, it's better to decompress it first. Otherwise, do this and check your emails or something :) – Max Williams Jul 4 '18 at 7:31

I'm using IBM and when using zcat, it will complains that it can't find the file ending with .Z.

On IBM one can use gzcat:

$ gzcat log_file.gz | less
  • What do you mean by "using IBM"? Do you mean AIX? – Duncan X Simpson Sep 29 '18 at 18:11
  • Using gzcat is also necessary on Solaris 5 – John Oct 24 '18 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.