Portable way to achieve ls' -v flag (i.e. sort by version)? Portable way to achieve ls' -v flag (i.e. sort by version)? unix unix

Portable way to achieve ls' -v flag (i.e. sort by version)?


sort -n -t- -k2 seems to do what you want. -n gives you numeric (i.e. not alphabetic) sort; -t- sets the field separator to -, and -k2 selects the second field, i.e. the version number.

My sort, on Ubuntu, even does the part with the underscore correctly, but I'm not sure if that is standard. To be sure, you could sort by the minor version first, then by major version.