The Linux sort Command: Sorting Lines
sort orders lines of text. Essential for organizing output.
Basic Usage
sort file.txtAlphabetical sort.
Numeric sort
sort -n numbers.txtNumeric values.
Reverse
sort -r file.txtDescending order.
Options
-n— Numeric sort-r— Reverse-u— Unique (dedupe)-k N— Sort by column N-t c— Field separator-h— Human numeric (1K, 1M)
Examples
Sort by column
sort -k2,2 -t',' data.csvSort by 2nd field.
Unique sorted
sort -u file.txtSort and remove duplicates.
