maux
Star on GitHub Buy me a coffee

Manual / sort

sort(1)

SORT(1) General Commands Manual SORT(1)

sort - sort or merge files

sort [-bcfmnru] [-t char] [-k N[type][,M[type]]] [-o file] [file...]

Sort sorts all the named files together and writes the result on the standard output. The standard input is used if no input file names are given. Thus sort may be used as a filter. The default sort key is an entire line. Default ordering is lexicographic in ASCII collating sequence.

Ignore leading blanks at the start of a key.
Check ordering; print no sorted output. Report the first disorder.
Fold lower case to upper case for comparison only.
Accept already sorted inputs for merging. This implementation still sorts the combined input normally.
Compare initial signed integer strings numerically. Leading blanks and zeroes are ignored; an absent number counts as zero.
Reverse the sense of comparisons.
Keep one line for each distinct key.
Separate fields at each occurrence of char, including empty fields.
Use fields N through M as a key, counted from 1; omit M for end of line. Without -t a field includes its leading blanks. Up to eight -k options may be given; they are tried in order. Each type is a run of the letters b, f, n, r: -b on the start field, -f fold case, -n numeric, -r reverse, for that key alone. A key with any type takes none of the global -b -f -n -r; a key with none takes them all. Types on N and on M are merged, and b on M changes nothing. The final whole-line comparison is reversed by the global -r only.
Write to file instead of standard output. It may also be an input: all input is read before the output is opened.

Equal keys use the whole line as a final ordering comparison, except that -u decides equality using the keys alone.

/usr/man/SORT this page

uniq(1), comm(1), licenses(1)

Exit status is 0 on success, 1 for disorder under -c, an input-open failure or a reported output-close failure; 2 for usage errors, insufficient storage or failure to create the output file.

All input and line pointers must fit in one process bank. Numeric comparison stops at a decimal point. The key types d and i, character positions (N.C), more than eight -k keys, and the old +pos/-pos notation are not implemented. Input-read errors are treated as end of file; not every output error is reflected in the exit status.

September 19, 2026 maux