coreutils: Details about version sort
1
1 10.1.4 Details about version sort
1 ---------------------------------
1
1 Version sorting handles the fact that file names frequently include
1 indices or version numbers. Standard sorting usually does not produce
1 the order that one expects because comparisons are made on a
1 character-by-character basis. Version sorting is especially useful when
1 browsing directories that contain many files with indices/version
1 numbers in their names:
1
1 $ ls -1 $ ls -1v
1 abc.zml-1.gz abc.zml-1.gz
1 abc.zml-12.gz abc.zml-2.gz
1 abc.zml-2.gz abc.zml-12.gz
1
1 Version-sorted strings are compared such that if VER1 and VER2 are
1 version numbers and PREFIX and SUFFIX (SUFFIX matching the regular
1 expression ‘(\.[A-Za-z~][A-Za-z0-9~]*)*’) are strings then VER1 < VER2
1 implies that the name composed of “PREFIX VER1 SUFFIX” sorts before
1 “PREFIX VER2 SUFFIX”.
1
1 Note also that leading zeros of numeric parts are ignored:
1
1 $ ls -1 $ ls -1v
1 abc-1.007.tgz abc-1.01a.tgz
1 abc-1.012b.tgz abc-1.007.tgz
1 abc-1.01a.tgz abc-1.012b.tgz
1
1 This functionality is implemented using gnulib’s ‘filevercmp’
1 function, which has some caveats worth noting.
1
1 • ‘LC_COLLATE’ is ignored, which means ‘ls -v’ and ‘sort -V’ will
1 sort non-numeric prefixes as if the ‘LC_COLLATE’ locale category
1 was set to ‘C’.
1 • Some suffixes will not be matched by the regular expression
1 mentioned above. Consequently these examples may not sort as you
1 expect:
1
1 abc-1.2.3.4.7z
1 abc-1.2.3.7z
1
1 abc-1.2.3.4.x86_64.rpm
1 abc-1.2.3.x86_64.rpm
1