1

Often, filenames are prefixed with characters like ~ to ensure they show up at the top of the directory when sorting alphabetically.

This begs the question, what is the full “alphabetical” order which includes these non-alphabetical and non-numerical characters?

For example, is there a similar character that always ends up at the bottom?

3
  • 2
    On most Unix-like OS's including Linux and MacOS, that is determined by the locale, the utility that is being used, how it is being sorted, the environment, and some other factors where applicable. With that being said, there is nothing that always ends up anywhere because those components aren't always the same. A single difference can alter what occurs. Commented Aug 10 at 20:27
  • 1
    Are you aware that locales exist? In the collation sequence of the POSIX locale the tilde is actually near the end. Commented Aug 10 at 20:28
  • One example is angstrom (Å) symbol, sorted before A in some cases, and after Z in others. There's no one answer, from A to Zed. Commented Aug 11 at 1:28

2 Answers 2

2

The order depends on the setting of the environment variables determined by locale.

$ LC_COLLATE=C ls
Aardvark  Baboon  Cat  apples  bananas  coconuts

$ LC_COLLATE="en_US.UTF-8" ls
Aardvark  apples  Baboon  bananas  Cat  coconuts

Taking that a little further

$ LC_COLLATE=C ls
'!'  "'"   0   6   '<'   B   H   N   T   Z    a   g   m   s   y    £
'"'  '('   1   7   '='   C   I   O   U  '['   b   h   n   t   z
'#'  ')'   2   8   '>'   D   J   P   V  '\'   c   i   o   u  '{'
'$'  '*'   3   9   '?'   E   K   Q   W   ]    d   j   p   v  '|'
 %    +    4   :    @    F   L   R   X  '^'   e   k   q   w  '}'
'&'   ,    5  ';'   A    G   M   S   Y   _    f   l   r   x  '~'

$ LC_COLLATE="en_US.UTF-8" ls
'!'  '('  ';'  '['  '|'   1   7   B   E   H   K   N   Q   T   W   Z
'"'  ')'  '<'  '\'  '}'   2   8   c   f   i   l   o   r   u   x
'#'  '*'  '='   ]   '~'   3   9   C   F   I   L   O   R   U   X
 %    +   '>'  '^'  '$'   4   a   d   g   j   m   p   s   v   y
'&'   ,   '?'   _    £    5   A   D   G   J   M   P   S   V   Y
"'"   :    @   '{'   0    6   b   e   h   k   n   q   t   w   z

Footnote: These are single character filenames. The quote marks are added by ls for filenames containing characters that are also shell meta characters with special meanings.

0

What is the full alphabetical order used on Linux and similar OSes?

Linux itself has no concept of "alphabetical order". Linux is an Operating System kernel, such high-level concepts belong in user space, not in the kernel.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .