Bash 5 reference · Text and System Tools

sort (Linux command)

Sort lines alphabetically, numerically, in reverse, by a key column, or with human-readable sizes; -u removes duplicates.

Bash 5

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

sort [OPTIONS] [FILE...]

Parameters

ParameterDescription
-n / -h Numeric / human sizes (2K, 1G).
-r Reverse.
-t, -k2 Sort by the second comma-separated field.
-u Unique lines only.
-V Version sort (1.9 before 1.10).

Examples

Text versus numeric
printf '10\n9\n100\n' | sort | tr '\n' ' '; echo
printf '10\n9\n100\n' | sort -n | tr '\n' ' '; echo

Output

10 100 9 
9 10 100 

Run this on your computer — see “Get Started” for setup.

By column, and versions
printf 'ana,31\nben,25\nchen,40\n' | sort -t, -k2 -nr
printf 'v1.10\nv1.9\n' | sort -V

Output

chen,40
ana,31
ben,25
v1.9
v1.10

Run this on your computer — see “Get Started” for setup.

Was this page helpful?