Forever & AlwaysLINUX COMMAND ATLAS

LINUX COMMAND ATLAS · COMMAND GUIDE

Linux sort command

Sort lines of text. Add -n for numeric order or -r for reverse order.

GNU Coreutils

Syntax

Command form
sort [OPTION]... [FILE]...

Common options

7 options
OptionWhat it does
-n, --numeric-sortCompare according to string numerical value.
-r, --reverseReverse the result of comparisons.
-u, --uniqueOutput only the first of equal lines.
-k, --key=KEYDEFSort by a selected field or character range.
-t, --field-separator=SEPUse SEP instead of whitespace between fields.
-h, --human-numeric-sortCompare human-readable numbers such as 2K and 1G.
-f, --ignore-caseFold lowercase letters to uppercase for comparison.

Usage examples

2 examples

Sort lines of text. Add -n for numeric order or -r for reverse order.

sort -n scores.txt

Sort colon-separated records by their third field numerically.

sort -t: -k3,3n /etc/passwd

Notes

Locale affects collation. For reproducible byte-oriented ordering, set LC_ALL=C; use -o when writing output to the input file.