30.3.2 Additional hard-coded priorities in GNU coreutils’ version sort

In GNU coreutils’ version sort algorithm, the following items have special priority and sort earlier than all other characters (listed in order);

  1. The empty string
  2. The string ‘.’ (a single dot character, ASCII 46)
  3. The string ‘..’ (two dot characters)
  4. Strings start with a dot (‘.’) sort earlier than strings starting with any other characters.


$ printf "%s\n" a "" b "." c  ".."  ".d20" ".d3"  | sort -V


These priorities make perfect sense for ‘ls -v’: The special files dot ‘.’ and dot-dot ‘..’ will be listed first, followed by any hidden files (files starting with a dot), followed by non-hidden files.

For ‘sort -V’ these priorities might seem arbitrary. However, because the sorting code is shared between the ls and sort program, the ordering rules are the same.