Is it possible to have the ls command behave differently based on the number of directory entries that may be listed?
If I just use ls
(with no modifying options, but I can specify directories or filters), I want it to:
- apply
-l
long listing format if there are 10 entries or less - show the first 50 entries only and output a warning that there are
x more entries
Is this possible? How can I do this?
Note that I don't want to use a custom script command switch to a custom command - I am OK with a custom script or wrapper, but I still want to use ls
to do this, with full functionality still maintained. That is, not my-custom-ls
but just ls
to call the script/wrapper.
ll() { ls -I "$@" | less; }
is similar, and much simpler and more predictable.ls -l | head -n 50
? what you want to do is possible with a lot of stuffing around (e.g. hacking and recompiling thels
source) but, more importantly, is not something you should want to do. success is likely to break many other things that expectls
to behave as the man page documents it to behave. Witness the recent complaints about GNUls
changing the default output to--quoting-style=shell-escape
or whatever it was changed to....it's arguably a much better output format but (cont)literal
quoting style.