SHARE
Facebook X Pinterest WhatsApp

Reading Compressed Files With less

Written By
thumbnail Juliet Kemp
Juliet Kemp
Jul 20, 2010
ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More



Juliet Kemp

less, the better-featured version of more, which among
other things allows you to move backward through its output, is great for
paging through text files. But it won’t automatically deal with compressed
text files. This can be a nuisance, particularly when many of the files in
/usr/share/doc are gzipped.

Tip of the Trade: Sometimes, less really is more. In the case of the app less, it is also the better-featured version of its bigger sibling, more.

A straightforward alternative is zless, which will deal seamlessly
with gzip, compress, or pack files, allowing you to page through them without
having to unzip them. It also handles uncompressed files, and
(contrary to the manpage) it appears to deal OK with input piped from stdin
(e.g., ls | zless).

Recent Tips
» tune2fs
» LDAP and Kerberos
» UUID

Read All Tips of the Trade

zless can’t, however, handle files that have been tarred as well
as zipped. Here’s an alternative command line that will allow you to page
through file.tar.gz without unpacking it beforehand and thus without
leaving unzipped files lying around:

tar --to-stdout -zxf file.tar.gz | less

That’s great, but it’s a bit of a mouthful (or keyboardful) to remember.
Try this instead (bash syntax):

export LESSOPEN="|tar --to-stdout -zxf %s"

Now try just typing less file.tar.gz. Magic!

In fact, this will deal with both uncompressed files and piped input as well, so you
can set this variable in your .bashrc. However, it won’t work
on plain .gz files – for those, you should still use
zless.

One last note: If you regularly want to look at tar archives that aren’t
also zipped (e.g., file.tar), you can set export LESSOPEN="|tar
--to-stdout -xf %s"
to work the same trick for these files.

thumbnail Juliet Kemp

Juliet Kemp is a ServerWatch contributor.

Recommended for you...

What Is a Container? Understanding Containerization
What Is a Print Server? | How It Works and What It Does
Nisar Ahmad
Dec 8, 2023
What Is a Network Policy Server (NPS)? | Essential Guide
Virtual Servers vs. Physical Servers: Comparison and Use Cases
Ray Fernandez
Nov 14, 2023
ServerWatch Logo

ServerWatch is a top resource on servers. Explore the latest news, reviews and guides for server administrators now.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.