sort — sort lines
cheat sheet · Ubuntu 24.04 · GNU coreutils 9.4 https://lab.dimsanych.ru/en/wiki/sort/Cheat sheet
-
sort file.txtalphabetical order -
sort -n nums.txtas numbers: 2 9 10 100 -
sort -rn nums.txtnumbers, largest first -
sort -k2,2 table.txtby the second field -
sort -t: -k3,3n /etc/passwd":" separator, field 3 -
sort -u names.txtsort and drop duplicates -
du -sh /var/log/* | sort -hsizes 4K 512M 1G -
sort | uniq -c | sort -rnline frequency, most common first
Options
Order letters can be attached to a key: -k3,3n is field 3 as a number, -k2,2r
is field 2 in reverse. The full list is in man sort.