man.lsPlain-English help for Unix commands

sort Sort lines of text

Reads lines and writes them back in order. By default it sorts as text, like a dictionary. Use it to tidy a list, to order a table by one column, or to prepare input for uniq.

Synopsis

sort [OPTION]... [FILE]...
sort -k START[,END] [-t SEP] [FILE]...

Common options

Option or formWhat it does
-nCompare as numbers, so 9 comes before 10. The default text order puts 10 before 9
-rReverse the order
-uOutput only the first of each run of equal lines, removing duplicates
-k START[,END]Sort on a field range instead of the whole line. Fields count from 1. -k2,2 means field 2 only
-t SEPUse SEP as the field separator for -k, for example -t, for CSV. The default separator is blank space
-fIgnore case when comparing
-hCompare human-readable sizes such as 2K, 1M and 3G, as printed by du -h
-o FILEWrite the result to FILE. Safe even when FILE is also the input

Examples

Sort a file alphabetically
sort words.txt
apple
apple
apple
fig
pear
pear
Sort and remove duplicates
sort -u words.txt
apple
fig
pear
Numbers as numbers, biggest first
printf '10\n9\n100\n' | sort -nr
100
10
9
Sort a CSV by score, highest first, then by name
sort -t, -k3,3nr -k1,1 data.csv
Sort a file in place
sort -o words.txt words.txt
Largest folders first
du -sh * | sort -rh | head

Notes

See also

Last reviewed 2026-10-07.