-
-
Notifications
You must be signed in to change notification settings - Fork 1
Linux sort Guide
Mattscreative edited this page Dec 5, 2025
·
2 revisions
Complete beginner-friendly guide to sort on Linux, covering Arch Linux, CachyOS, and other distributions including sorting text, data organization, and file sorting.
sort sorts lines of text.
Uses:
- Sort text: Organize text files
- Data organization: Sort data
- Remove duplicates: Unique lines
- Merge files: Combine sorted files
Why it matters:
- Organization: Organize data
- Data processing: Process text files
- Scripting: Useful in scripts
Sort file:
# Sort file
sort file.txt
# Alphabetical orderSave sorted:
# Sort and save
sort file.txt > sorted.txt
# Or in place (with sponge)
sort file.txt | sponge file.txtDescending:
# Reverse sort
sort -r file.txt
# Descending orderNumbers:
# Numeric sort
sort -n file.txt
# Sorts numbers correctlyRemove duplicates:
# Unique lines only
sort -u file.txt
# Or
sort file.txt | uniqField sorting:
# Sort by field
sort -t',' -k2 file.csv
# -t: Delimiter
# -k: Key (field)Complex sorting:
# Sort by multiple fields
sort -t',' -k1,1 -k2,2n file.csv
# Primary: field 1
# Secondary: field 2 (numeric)Check file:
# Verify file exists
ls -la file.txt
# Check encoding
file file.txtThis guide covered sort usage, text sorting, and data organization for Arch Linux, CachyOS, and other distributions.
- sed and awk Guide - Text processing
- cut Guide - Field extraction
- uniq Guide - Remove duplicates
-
sort Documentation:
man sort
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.