Unix's 'ls' sort by name
My ls sorts by name by default. What are you seeing?
man ls
states:
List information about the FILEs (the current directory by default). Sort entries alpha‐betically if none of -cftuvSUX nor --sort is specified.
:
For something simple, you can combine ls with sort. For just a list of file names:
ls -1 | sort
To sort them in reverse order:
ls -1 | sort -r
ls
from coreutils
performs a locale-aware sort by default, and thus may produce surprising results in some cases (for instance, %foo
will sort between bar
and quux
in LANG=en_US
). If you want an ASCIIbetical sort, use
LANG=C ls