The sort command
Sort lines of text. Prints the lines of the files (or of what is piped into it) in order. Upper and lower case sort together, like a dictionary.
Usage
sort [OPTION]... [FILE]...
Options
| -n, --numeric-sort | sort by the number at the start of each line, so 9 comes before 10 |
|---|---|
| -r, --reverse | reverse the order |
| -u, --unique | print each distinct line once |
| -f, --ignore-case | treat upper and lower case as the same when comparing |
| -k N | sort by the Nth word of each line instead of the whole line |
Examples
sort names.txtAlphabetical ordersort -n scores.txtSmallest number firstsort fruit.txt | uniq -c | sort -nrCount each line, most common first
Learn it step by step
Related commands
learner@sandbox: ~bash (practice)
Note: Try sort here: your home directory has sample files. Press Try beside an example, or type your own.
Enter runs · Tab completes names · ↑ ↓ step through history · Ctrl+L clears · type help for every command
A practice shell in your browser that behaves like bash on Linux for these commands. Nothing you type leaves the page.