Very often I find myself looking through directories using 'ls', then when I find the file I want, I use 'less' to look at the file.
So for example to find a mysql log file I might type
ls /var
then:
ls /var/log/
and then:
ls /var/log/mysql
and finally:
less /var/log/mysql/mysql.log
(its a bit of a contrived example, but hopefully you know what I am doing)
I find it annoying that I need to decide if the command should be ls or less.
Why can't 'less' determine if it has been given a directory and act as 'ls' ?
Is there a command that I can use instead of less that will act as ls or less depending on the file type ? Or is there a common alias that people use ?
Best Answer
Less can determine if it has been given a directory. Set the
LESSOPEN
environment variable to~/bin/LESSPIPE
and make~/bin/LESSPIPE
a script like the following:You'll get a listing for directories and archives.
You can use
lesskey
instead of the environment variable to set the preprocessor. See the documentation for details.