"less" doesn't automatically decompress gzipped files

less do not do that by default, but there is a line in the default ~/.bashrc that change the default behavior:

[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

Be sure to not remove or comment this line.
With this in place, you can page zipped and non-zipped files without knowing, like in

less /var/log/dpkg.log*

where some of the logs can be zipped and some others non-zipped.

For the root account accessed through sudo you cannot do the same thing, but there are two workarounds:

  1. sudo zless file*
  2. sudo -E less file*

In the first case I used zless, that works also for non-zipped file.
In the second one I added the -E option to sudo to preserve your environment variables, to make less work as you would expect.


Less can't read gzipped files, you can check it in its man page. There is a script, installed by default in Ubuntu and most distros, called zless, that works as you described.

So the answer is to use:

zless my_stuff.csv.gz

The difference between Fedora and Ubuntu is that Fedora set the environment variable LESSOPEN to force the argument through lesspipe:

echo $LESSOPEN
||/usr/bin/lesspipe.sh %s

Note that this command is not going to work in Ubuntu.

Tags:

Gzip

Less