Less is more: the hidden treasure of less command

less is a pager or a program similar to more, but which allows backward movement in the file as well as forward movement. Less has a massive number of options. Every time I work with less command, I find something new and amazing. less is capable of displaying not just a text file but it can display an ISO image, a PDF file or even a MS word doc file contains from shell prompt. Sometime it saves lots of my time:

Watch a log file
Watch maillog in real time, useful to troubleshoot mail server problem
less +F /var/log/maillog
less +F /var/log/message
You can also use tail command:

tail -f /var/log/maillog

Start to display at a specific part in the file
# httpd -tOutput:

Syntax error on line 53 of /etc/httpd/httpd.conf

Ok let us display an error at line number 53 (no need to scroll down all 52 lines)# less +53 /etc/httpd/httpd.confSearch and highlight particular text:# less "+/*VirtualHost" /etc/httpd/httpd.confUse less preprocessor to display following extensions files on screen
lessfile and lesspipe are programs that can be used to modify the way the contents of a file are displayed in less. What this means is that less can automatically open up tar files, uncompress gzipped files, and even display something reasonable for graphics files. Just put the following command in your login script (if you are using bash put in ~/.bash_profile):
$ vi ~/.bash_profileAppend following line:eval "$(lesspipe)"Save file and load the changes:

. ~/.bash_profile

a) Display a PDF File:$ less file.pdfb) Display a MS-Word File:$ less file.docc) Display listing of tar file (and other compressed files):$ less myfile.tar
$ less myfile.tar.gz
d) Display an ISO image file listing without mounting them (remember to mount an ISO file you need to have a root account permission):$ less KNOPPIX_V4.0.2CD-2005-09-23-EN.isoe) Display .deb or rpm file information and file listing (useful to find out where files going to install):$ less foo.deb
$ less foo.rpm
less command supports following extensions:

  • *.arj
  • *.tar.bz2
  • *.bz
  • *.bz2
  • *.deb, *.udeb
  • *.doc
  • *.gif, *.jpeg, *.jpg, *.pcd, *.png, *.tga, *.tiff, *.tif
  • *.iso, *.raw, *.bin
  • *.lha, *.lzh
  • *.pdf
  • *.rar, *.r[0-9][0-9]
  • *.rpm
  • *.tar.gz, *.tgz, *.tar.z, *.tar.dz
  • *.gz, *.z, *.dz
  • *.tar
  • *.jar, *.war, *.xpi, *.zip
  • *.zoo

Finally, lesskey command lets you change the meaning of any key or sequence of keys for less command. lesskey man page has detailed information on this topic. Read man page of less command for more info.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 8 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
8 comments… add one
  • Anonymous Mar 11, 2006 @ 16:41


    may I ask what wonderous version of less you are using?

    When viewing .jpg or .iso file less asks me “may be a binary file. See it anyway?” and then displays binary gibberish. 8-(

    $ less –Version
    less 382+iso254

  • LinuxTitli Mar 11, 2006 @ 17:38

    Hi there,

    less –version
    less 394

    I hope you have added following line to your .bash_profile (shell startup file):
    eval “$(lessfile)”

    Hope this helps.

  • goku Mar 11, 2006 @ 17:43

    I am using Gentoo and it worke after upgrading less version 🙂 may be you need an updated version of less.

    Nice find especially displaying a PDF/doc files over remote ssh session. Last time I had to configure qmail and all information was in a PDF file. Therefore, I had taken printout of over 30+ pages from windows box.

  • Anonymous Mar 11, 2006 @ 17:48

    less SUSE-9.3-Prof-i386-CD1.iso

    CD-ROM is in ISO 9660 format
    System id: LINUX
    Volume id: SU930.F01
    Volume set id:
    Publisher id: Novell, Inc.
    Data preparer id: CD-Team, http://www.suse.de/feedback
    Application id: SuSE-Linux-Professional-FTP-i386-9.3#0
    Copyright File id:
    Abstract File id:
    Bibliographic File id:
    Volume set size is: 1
    Volume set sequence number is: 1
    Logical block size is: 2048
    Volume size is: 356178
    El Torito VD version 1 found, boot catalog is in sector 265
    Joliet with UCS level 3 found
    Rock Ridge signatures version 1 found
    Eltorito validation header:
    Hid 1
    Arch 0 (x86)
    ID ‘Novell, Inc.’
    Key 55 AA
    Eltorito defaultboot header:
    Bootid 88 (bootable)
    Boot media 0 (No Emulation Boot)
    Load segment 0
    Sys type 0
    Nsect 4
    Bootoff 10A 266



  • Anonymous Mar 11, 2006 @ 18:36

    $ less foo.rmp
    should be
    $ less foo.rpm

  • Anonymous Mar 11, 2006 @ 20:20


    it seems those are features of the cutting edge less 394.

    With less 382 I seem to have no “lessfile” nor “lesspipe”.

    Those features would be nice to have.

    Anyway, nice article. 😎

  • LinuxTitli Mar 11, 2006 @ 20:45

    Okai typo fixed. Thanks for the heads up

  • jp Feb 18, 2008 @ 9:13

    if i use “ls -l | less -C” option, the output it shows covers the full screen. But i want only the output of that command alone, which will be less than half page. What is the option to give with less? Thanks.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum