Name

sort

Synopsis

    sort [options] [files]

Sort the lines of the named files, typically in alphabetical order. See also uniq, comm, and join.

Mac OS X uses an early version of GNU sort that lacks long options as well as some of the features of the current GNU sort.

Common Options

-b, --ignore-leading-blanks

Ignore leading spaces and tabs.

-c, --check

Check whether files are already sorted, and if so, produce no output.

-d, --dictionary-order

Sort in dictionary order (ignore punctuation).

-f, --ignore-case

“Fold”; ignore uppercase/lowercase differences.

-i, --ignore-nonprinting

Ignore nonprinting characters (those outside ASCII range 040-176).

-kfieldspec, --key=fieldspec

Specify significance of input fields for sorting. See the fuller description below.

-m, --merge

Merge sorted input files.

-M, --month-sort

Compare first three characters as abbreviations for month names (Jan < Feb, etc.).

-n, --numeric-sort

Sort in arithmetic (numerical) order.

-ofile, --output=file

Put output in file.

-r, --reverse

Reverse the order of the sort.

-tc, --field-separator=c

Fields are separated with c (default is any whitespace).

-Tdir, --temporary-directory=dir

Use dir for temporary files.

-u, --unique

Identical lines in input file appear only one (unique) time in output.

+n[-m]

Skip n fields before sorting, and sort up to field position m. If m is missing, sort to end of line. Positions take the form a.b, which means character b of field a. If .b is missing, sort at the first character of the field. Counting starts at zero. Fields ...

Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.