Sorting file content
Linux Command Line Quick Reference
1 min read
This section is 1 min read, full guide is 20 min read
Published Aug 18 2026
19
Show sections list
0
Log in to enable the "Like" button
0
Guide comments
0
Log in to enable the "Save" button
Respond to this guide
Guide Sections
Guide Comments
CLILinuxUbuntu
sort orders lines of text. It reads a file or standard input and writes the sorted result to standard output.
Sort text
bash
sort names.txtsort -r names.txtsort -n numbers.txtsort -h sizes.txtsort -u names.txtsort -t, -k2,2 data.csvsort input.txt > sorted.txt-r reverses the order. -n compares values numerically instead of alphabetically. -h understands human-readable sizes such as 2K and 1G. -u outputs one copy of equal lines. -t sets the field delimiter and -k selects the key used for sorting.
uniq operates on adjacent equal lines, so it is commonly used after sort:
Count or remove duplicate lines
bash
sort names.txt | uniqsort names.txt | uniq -csort names.txt | uniq -duniq -c counts occurrences and -d prints only duplicated values.