Sorting file content

Linux Command Line Quick Reference

1 min read

Published Aug 18 2026


19
0
0
0

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 -d

uniq -c counts occurrences and -d prints only duplicated values.

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact
Linux Command Line Quick Reference | Sorting file content | SimpleSteps.guide