Making less read non-text files


less

I always tell my students how nice is less compared to more (both are paging programs) . One feature of less I emphasize is the ability to read non-text files. For instance, you can try to read a compressed file like this one /usr/share/doc/coreutils/README.gz using more:

more /usr/share/doc/coreutils/README.gz

Now using less:

less /usr/share/doc/coreutils/README.gz

Did you see any difference? if you’re using Ubuntu, maybe you could read the file using less. If you’re using Debian maybe you couldn’t…and let’s see why.

Making less read non-text files on Debian

It turns out less can read non-text files because it uses “input preprocesors”, which basically are  scripts that preprocess the file before using less. So, what’s the difference between Debian and Ubuntu’s settings?. On Ubuntu every user has two environment variables set, and on Debian they don’t (at least on testing). Those variables are:

LESSCLOSE='/usr/bin/lesspipe %s %s'
LESSOPEN='| /usr/bin/lesspipe %s'

You can define them in the ~/.bashrc file, but there’s a better way to do it,  just uncomment the following line in the ~/.bashrc file:

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

Next time you open a bash session you’ll have those variables set, so you’ll be able to open non-text files using less.

less
Share this:
  • Twitter
  • Facebook
  • Identi.ca
  • del.icio.us

Related posts:

  1. Adding subtitles to avi files
  2. Reversing order of PDF files
  3. How to split large files on Linux
  4. Unloking Gnome-Keyring in Slim
  5. Running VirtualBox from GDM

  1. César Mata Moya

    #1 by César Mata Moya on 16/11/2009 - 8:08 pm

    Esta bueno el tip…

  2. Luis Gallardo

    #2 by Luis Gallardo on 16/11/2009 - 8:47 pm

    Si, sobre todo porque la mayoría de la documentación en Debian viene comprimida :)

(will not be published)

Switch to our mobile site