How this tool works
Sorting is locale-aware rather than a comparison of raw character values, so accented and non-Latin letters fall where a reader of that language expects instead of being pushed past Z. Five orderings are available: alphabetical, natural, numeric, by length, and a shuffle. The first four are stable orderings you can reverse; the shuffle is a Fisher-Yates pass over the list, which gives every arrangement an equal chance and ignores the direction setting entirely.
Natural order treats runs of digits inside a line as numbers, which is why it puts file2 before file10 where plain alphabetical order does not. Numeric order looks for the first number anywhere in each line — negative and decimal values included — and sorts on that, sending lines with no number in them to the end. Sorting by length compares character counts and breaks ties alphabetically so that equal-length lines still come out in a predictable order.
Picking an ordering that matches your data
- Alphabetical is character order, not human order: anything with numbers in it — versions, filenames, invoice references — sorts by digit rather than by value. Natural order is the fix.
- Numeric reads the first number it finds: a line beginning with a date or an identifier sorts on that number rather than the one you meant. Natural order is often the better choice for mixed lines.
- Descending reverses after sorting: which also moves the lines that have no number in them from the end to the beginning.
- The shuffle is genuinely random each run: run it twice and you get two different orders. Nothing about direction or case applies to it.