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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Use zcat, then pipe it to less.
$ zcat $FILE | less
Method 2
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:
#env LESSOPEN=|/bin/lesspipe %s
Method 3
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
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0