Read a gzipped text file directly with less.

less textfile.gz
There is no need to 'zcat textfile.gz | less' with newer distros. This is useful for reading archived log files without having to extract, read, and zip when done.

By: allbad
2009-03-15 23:51:17

What Others Think

Again, 'less' can't do this. Read the man page. zcat textfile.gz | less
atoponce · 688 weeks and 6 days ago
it's working, but it's more handy for me: zcat file.gz |grep stuff |more
gladia2r · 688 weeks and 5 days ago
and again. Yes, less can do this.
elzapp · 688 weeks and 5 days ago
atoponce is right. Read the man page. The less version 418 manpage has no hits for 'gzip' or 'gz' strings when I just searched it. So I don't think less *the program* supports this. However, it's possibly that your system is setup in such a way that you *think* less does. In some distributions, I believe less actually invokes 'zless', which is a bash script (/bin/zless) on my ubuntu system. I remember when I used to run gentoo that, I think, the less->zless link was present. If your file was gzip compressed, then it displayed properly, yay, but if not, it displayed OK too. The other way less may support gzip-compressed files is hinted at in the manpage for zless, and documented in the less manpage, under the "INPUT PREPROCESSOR" section. That method is to set some environment variables for less, such that it uses other tools to first filter (uncompress, here) the file before displaying it. So I normally try: zless textfile.gz Back in 2004, their was a wapper script for less and more posted on a debian mailing list which would uncompress files: So some day when you invoke less, the "right thing" will happen and the terminal will display your file for you - but it's not due to less, it's due to a wrapper script or (more crude) symlink.
bwoodacre · 688 weeks and 5 days ago
Less cannot do this, however many systems have wrapped less up so that if given a .gz file it will uncompress it and pipe it through zless is an explicit filter that does this, and will work for gzipped files that do not end in .gz
ant · 688 weeks and 4 days ago
zless is nothing more than a bash script hack. It invokes gzip, pipes it to STDOUT, and uses less to parse the output. As such, surprise, surprise, less doesn't read binaries, including gzip files. People need to spend time reading the docs, and learning their system.
atoponce · 688 weeks and 4 days ago
Ubuntu and Fedora both set environment vars: Ubuntu: set | grep -i less LESSCLOSE='/usr/bin/lesspipe %s %s' LESSOPEN='| /usr/bin/lesspipe %s' Fedora: set | grep -i less LESSOPEN='|/usr/bin/ %s' is a shell script that handles adapting the input to work with less.
bitmage · 688 weeks and 3 days ago
@bitmage you are called bitMAGE for a reason! I didn't know this either, nor did I believe it. But I was convinced once I hacked in the following one-liner into /usr/bin/lesspipe: echo "calling $0" && sleep 2 Guess what, the echo line came up, so this stuff *IS* routed via lesspipe. Well spotted. I hope that this myth has ended once and for all that "new less version can even 'load gzipped files'". (Unlike tar, where you can INDEED use tar xvf to unpack (pk)zipped files (only legit way in older versions was: tar zxvf)
syntaxerror74 · 390 weeks and 3 days ago
So glad to get this weblog how to get free v-bucks very helpful for robux game .
ethan81 · 39 weeks and 4 days ago
seofox · 27 weeks and 1 day ago ????? ??? ????? ???? SEO ????? ????? ????? ???? ????? ????? ??? ???? ???? ??????? Search Engine Optimization ??? ????? ??????????? ?? ????? ?????????? ????? ????? ?? ????
seofox · 16 weeks and 6 days ago
seofox · 15 weeks and 4 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: