sort command
Sort lines of text alphabetically, numerically or by column.
- Text processing
- Package coreutils
- 8 options · 8 examples
Syntax
sort [options] [file…]Provided by the coreutils package. Run man sort for the full manual.
Common options
| Option | What it does |
|---|---|
-n | Numeric sort |
-h | Human-readable numbers (2K, 1G) |
-r | Reverse the order |
-k N | Sort by column N |
-t SEP | Column separator |
-u | Remove duplicate lines |
-o FILE | Write to a file (can be the input) |
-V | Version sort (1.2 < 1.10) |
Examples
Sort alphabetically
sort names.txtNumeric sort
sort -n numbers.txtLargest first
sort -rn sizes.txtSort du output by size
du -sh * | sort -hSort by the 3rd column
sort -k3 -n data.txtSort a CSV by column 2
sort -t, -k2 data.csvSort and remove duplicates
sort -u emails.txtSort a file in place
sort -o list.txt list.txt
No example matches. Check the options table or search the guides.
sort guides
- Sort Command in Linux with Practical Examples Linux Commands · Updated Apr 2025
