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

Solution 1:

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.

Solution 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.