11

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.

2 Answers 2

6

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.

4

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .