Let's say I have a directory with the files _b
, a
, c
, č
, d
. I would like to sort the files according to the cs_CZ.UTF8 locale but without ignoring the underscore, ie like this: _b a c č d
.
Currently, ls
(and ls | sort
as well) sorts the files like this: a _b c č d
.
All answers I have found suggest using LC_COLLATE=C
, but that changes the ordering to
this: _b a c d č
(notice that č
is now at the end, not between c
and d
as it is supposed to be).
Is there any way to achieve this goal?
Note that I also care about other characters than underscore, ie I would like a-n.pdf a-p.pdf a.pdf c č d
sort in this order and not a-n.pdf a.pdf a-p.pdf c č d
.
(EDIT: Actually, a.pdf a-n.pdf a-p.pdf c č d
is also fine, as long as the non-alphanumeric characters are not ignored.)
The following are not the answers I am looking for:
- using
LC_COLLATE=C
as explained above, - using shell expansion such as
ls _*; ls [^_]*
because the question is not only about underscores.
[locale]
tag also. Have you looked at https://unix.stackexchange.com/q/421908/90290 and https://unix.stackexchange.com/q/39827/90290 yet? – Mark Stewart Oct 13 '21 at 23:37a.pdf a-n.pdf a-p.pdf
is OK, as isa-n.pdf a-p.pdf a.pdf
, but nota-n.pdf a.pdf a-p.pdf
as that clearly ignores the hyphens/periods. I have tried to clarify this in the question. – Nikola Benes Oct 14 '21 at 13:58version1.txt
,version2.txt
, ...version10.txt
does sort "correctly" withversion10.txt
at the end. – Mark Stewart Oct 14 '21 at 14:18