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
Syntax
sort [OPTIONS] [FILE...]
Parameters
| Parameter | Description |
|---|---|
-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
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.
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.
Related
uniq· Remove or count adjacent duplicate lines; sort first, then use -c to count occurrences or -d to show only duplicates.cut· Extract columns from each line by delimiter and field number, or by character positions.- Bash sort, uniq, cut and tr · tutorial