The Less command can list directory contents in Gentoo Linux, but not in Ubuntu Linux

6

I regularly use the 'less' command in Gentoo like so: less /tmp (or any other directory, which I have access to.)

Less then proceeds to show me the contents of that directory. I can also use Less to show the contents of files (the usual use case).

In Ubuntu (Oneiric) when executing the above command, Less reports: /tmp is a directory

Less will not list the contents of the directory.

I am using Less version 444 in both operating systems.

Can anyone help? I have been unsuccessful searching online.

Thanks in advance.

Richard

Posted 2012-05-12T09:37:19.543

Reputation: 61

Answers

2

Check out the README.gentoo file in

/usr/portage/sys-apps/less/files

The behavior of less is customized by a lesspipe.sh script (in that same directory). If the argument passed is a directory, lesspipe.sh does ls -alF on it and that is what less pages.

See the less man page, Input preprocessor section for additional information. You can probably pick up Gentoo's lesspipe.sh and put it on your Ubuntu system without much hassle.

Mat

Posted 2012-05-12T09:37:19.543

Reputation: 6 193

2

Lesspipe is part of the less package on Ubuntu (Precise, at least), and is probably already installed on your computer.

Put this command in a login script, for instance ~/.bash_login:

eval $(lesspipe)

Then put this content in ~/.lessfilter

#!/bin/sh

# show directory as listing
if test -d "$1"; then
 /bin/ls -alF -- "$1"

 # we handled this one ourself
 exit 0
fi

# handle by regular lesspipe
exit 1

And make this file executable:

chmod +x ~/.lessfilter

Directories should now be shown as long format listings.

RolKau

Posted 2012-05-12T09:37:19.543

Reputation: 826