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.

-5
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 · 878 weeks and 1 day ago
it's working, but it's more handy for me: zcat file.gz |grep stuff |more
gladia2r · 878 weeks and 1 day ago
and again. Yes, less can do this.
elzapp · 878 weeks and 1 day 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 · 878 weeks 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 · 878 weeks 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/lesspipe.sh %s' lesspipe.sh is a shell script that handles adapting the input to work with less.
bitmage · 877 weeks and 5 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 · 579 weeks and 5 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?

commandlinefu.com 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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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: