Skip to content

sort command

Sort lines of text alphabetically, numerically or by column.

On this page

Syntax

sort [options] [file…]

Provided by the coreutils package. Run man sort for the full manual.

Common options

OptionWhat it does
-nNumeric sort
-hHuman-readable numbers (2K, 1G)
-rReverse the order
-k NSort by column N
-t SEPColumn separator
-uRemove duplicate lines
-o FILEWrite to a file (can be the input)
-VVersion sort (1.2 < 1.10)

Examples

  1. Sort alphabetically

    sort names.txt
  2. Numeric sort

    sort -n numbers.txt
  3. Largest first

    sort -rn sizes.txt
  4. Sort du output by size

    du -sh * | sort -h
  5. Sort by the 3rd column

    sort -k3 -n data.txt
  6. Sort a CSV by column 2

    sort -t, -k2 data.csv
  7. Sort and remove duplicates

    sort -u emails.txt
  8. Sort a file in place

    sort -o list.txt list.txt

sort guides

← All Linux commands · Suggest a fix

Back to top