cga2000 wrote: > I wanted to sort the output of the ls command by filename and with > directories first and regular files last. > > What I came up with does not quite behave as I expected: > > $ ls -al --color=never | sort -k1.1,1.1r -k8f
You shouldn't ever need --color=never there unless you have aliased ls with ls --color=always. You don't want ls --color=always (really you don't) and therefore you won't need to undo it with --color=never. > Why does .efile appear together with my other two [Ee]file's rather than > just below .clewn_keys? > > Looks like sort is ignoring the dots .. ?? You probably have set a locale setting that ignores punctuation. > Side-effect of the "f" flag specified with my second sort key ..? No. > Something to do with my locale (en_US)? Yes. If a locale is set then the collation sequence for the locale is used. This is controlled outside of sort (and also ls and bash and anything else that produces sorted output) and must be respected if set. http://www.gnu.org/software/coreutils/faq/#Sort-does-not-sort-in-normal-order_0021 Apparently the people who defined the collating sequence for the en_* locales confused working with data on a computer with working with text on a computer. The locale collating sequences for en_* ignores punctuation and folds case by default! I have set the following in my environment to restore a standard sort ordering: export LANG=en_US.UTF-8 export LC_COLLATE=C Bob