What does sort do?
sort puts lines in order — alphabetically by default, numerically with -n, reversed with -r.
sort [options] [file]
Most useful options
| Option | What it does |
|---|---|
| -n | numeric |
| -r | reverse |
| -u | remove duplicates |
| -k 2 | sort by column 2 |
| -h | human sizes (2K, 1G) |
sort examples
In security work
sort | uniq -c | sort -nr finds the top attacking IPs in seconds.
Questions about sort
Why do I need sort before uniq?
uniq only removes duplicates that are next to each other, so sort first.