ls
has no option to do that, but one of the nice things about unix & linux is that long-winded and inelegant pipelines can easily be turned into a shell script, function, or alias. and these can, in turn, be used in pipelines just like any other program.
(NOTE: there are some scope issues with functions and aliases. Scripts are available to any executable that can read and execute them. Aliases and functions are only available in the current shell - although a sub-shell's .profile/.bashrc etc may redefine them and thus make them available. Also, a script can be written in any language - including bash/sh, awk, perl, python, and others - whichever one is best for the job or that you are most familiar with)
e.g.
alias lsf='find . -maxdepth 1 -type f -print0 | xargs -0r ls'
I've added xargs so that you can use use all the usual ls
options, e.g. lsf -lrS
Because it uses find
, all of the normally-hidden dotfiles will be displayed, and all of the filenames will be prefixed with ./ - that's about the only difference you'll notice.
You could exclude dot files with ! -iname '.*'
but then you'd have to have two versions of the alias - one that displayed dot files and one that didn't.
alias lsf2='find . -maxdepth 1 -type f -a ! -iname '\''.*'\'' -print0 | xargs -0r ls'
Alternatively, if lsf
was a script rather than an alias you could parse the options (perhaps with getopts or /usr/bin/getopt or similar), and exclude dotfiles unless -a
was present.
find
command is the best way to do what you want. For some reliable other options, you should look into shell specific commands (and those are anything but portable)!ls -d */
, which is short, easy to type, and easy to understand. So I'm pretty happy with Ulrich Dangel's answer, even though I'm not using zsh.ls
offers a load of switches like thatfind
doesn't.find
is notls
.-type f
Thanks.