sort <file>Sorts lines alphabetically.
Example
sort names.txtSorts lines of text alphabetically, numerically, by field or by human-readable size.
sudo apt install coreutilssort <file>Sorts lines alphabetically.
Example
sort names.txtsort -r <file>Reverse order.
Example
sort -r names.txtsort -n <file>Numeric sort, so 10 comes after 9.
Example
sort -n numbers.txtsort -h <file>Sorts human-readable sizes like 4K, 2M and 1G correctly.
Example
du -sh * | sort -hsort -u <file>Sorts and removes duplicates in one step.
Example
sort -u ips.txtsort -f <file>Ignores case.
Example
sort -f words.txtsort -t<sep> -k<n> <file>Sorts by field n using a delimiter — here, by UID.
Example
sort -t: -k3 -n /etc/passwdsort -k<n>,<n>nr <file>Sorts by one field numerically in reverse; limiting the key to n,n stops it spilling into later fields.
Example
sort -k2,2nr scores.txtsort -V <file>Version sort: 1.2 < 1.10.
Example
sort -V versions.txtsort -t. -k1,1n -k2,2n -k3,3n -k4,4n <file>Sorts IPv4 addresses numerically, octet by octet.
Example
sort -t. -k1,1n -k2,2n -k3,3n -k4,4n ips.txtsort -o <file> <file>Writes the result back to the same file safely (unlike > list.txt).
Example
sort -o list.txt list.txtsort -R <file>Shuffles lines randomly.
Example
sort -R wordlist.txtsort --parallel=<n> -S <size> <file>Uses more threads and memory for very large files.
Example
sort --parallel=4 -S 2G huge.txtsort -c <file>Checks whether a file is already sorted.
Example
sort -c ids.txt