How to Sort Lines of Text in Linux (sort)

sort orders the lines of a file or piped input alphabetically or numerically.

Published October 2, 2026

sort orders the lines of a file or piped input alphabetically or numerically.

Key points

  • sort -n sorts numerically instead of the default lexicographic (string) order, where "10" would otherwise sort before "2"
  • sort -r reverses the sort order
  • sort -k2 sorts based on the second whitespace-separated column instead of the whole line

Example

sort -n numbers.txt
More Linux articles