Windows
Linux
Text Processing
Windows sort equivalent in Linux
Sorts the lines of a text file or input alphabetically, numerically, or by other criteria.
Windows
→
sort
Linux equivalents
sort
sort
sort
Overview
What this command does
Sorts the lines of a text file or input alphabetically, numerically, or by other criteria.
Migration tip: Linux
sort is much more powerful than Windows. Combine with uniq to remove duplicate lines.Practical tasks
Common use cases
Sort lines of text
Sorts the lines of a text file or input alphabetically, numerically, or by other criteria.
sort -r
Reverse order (Z to A)
sort -n
Numeric sort (10 comes after 9)
sort -u
Sort and remove duplicates
Ready to run
Copyable Linux commands
Review paths, device names, package names and permissions before running any command.
sort file.txt
sort -r file.txt
sort -n numbers.txt
sort -u file.txt
cat names.txt | sort | uniq
ls -la | sort -k 5 -n
Walkthrough
Examples with explanations
# Windows: sort file.txt
sort file.txt # alphabetical sort
sort -r file.txt # reverse order
sort -n numbers.txt # numeric sort
sort -u file.txt # sort + remove duplicates
# Sort and pipe:
cat names.txt | sort | uniq # unique sorted names
ls -la | sort -k 5 -n # sort dir listing by file size
Reference
Common options and variations
| Command or option | Use |
|---|---|
sort -r | Reverse order (Z to A) |
sort -n | Numeric sort (10 comes after 9) |
sort -u | Sort and remove duplicates |
sort -k 2 | Sort by second column/field |
sort -t ',' -k 2 | Sort CSV by second column |
Distro differences
Debian/Ubuntu vs Fedora vs Arch
This command is the same on Debian/Ubuntu, Fedora and Arch Linux when the relevant tool is installed.
| Distribution | Package manager / base | Equivalent command | Difference to notice |
|---|---|---|---|
| Debian/Ubuntu | same command | sort |
Same command on this distribution. |
| Fedora | same command | sort |
Same command on this distribution. |
| Arch | same command | sort |
Same command on this distribution. |
Keep learning