sort
sort [OPTION]... [FILE]...
Display sorted concatenation of all FILE(s). With no FILE, or when FILE is -, read standard input.
Options
--help-
Print help information.
--version-
Print version information.
--sort--human-numeric-sort,-h-
compare according to human readable sizes, eg 1M > 100k
--month-sort,-M-
compare according to month name abbreviation
--numeric-sort,-n-
compare according to string numerical value
--general-numeric-sort,-g-
compare according to string general numerical value
--version-sort,-V-
Sort by SemVer version number, eg 1.12.2 > 1.1.2
--random-sort,-R-
shuffle in random order
--random-source=<FILE>-
use FILE as a source of random data
--dictionary-order,-d-
consider only blanks and alphanumeric characters
--merge,-m-
merge already sorted files; do not sort
--check,-c-
check for sorted input; do not sort
--check-silent,-C-
exit successfully if the given file is already sorted, and exit with status 1 otherwise.
--ignore-case,-f-
fold lower case to upper case characters
--ignore-nonprinting,-i-
ignore nonprinting characters
--ignore-leading-blanks,-b-
ignore leading blanks when finding sort keys in each line
--output=<FILENAME>,-o <FILENAME>-
write output to FILENAME instead of stdout
--reverse,-r-
reverse the output
--stable,-s-
stabilize sort by disabling last-resort comparison
--unique,-u-
output only the first of an equal run
--key,-k-
sort by a key
--field-separator,-t-
custom separator for -k
--zero-terminated,-z-
line delimiter is NUL, not newline
--parallel=<NUM_THREADS>-
change the number of threads running concurrently to NUM_THREADS
--buffer-size=<SIZE>,-S <SIZE>-
sets the maximum SIZE of each segment in number of sorted items
--temporary-directory=<DIR>,-T <DIR>-
use DIR for temporaries, not $TMPDIR or /tmp
--compress-program=<PROG>-
compress temporary files with PROG, decompress with PROG -d; PROG has to take input from stdin and output to stdout
--batch-size=<N_MERGE>-
Merge at most N_MERGE inputs at once.
--files0-from=<NUL_FILE>-
read input from the files specified by NUL-terminated NUL_FILE
--debug-
underline the parts of the line that are actually used for sorting
The key format is FIELD[.CHAR][OPTIONS][,FIELD[.CHAR]][OPTIONS].
Fields by default are separated by the first whitespace after a non-whitespace character. Use -t to specify a custom separator. In the default case, whitespace is appended at the beginning of each field. Custom separators however are not included in fields.
FIELD and CHAR both start at 1 (i.e. they are 1-indexed). If there is no end specified after a comma, the end will be the end of the line. If CHAR is set 0, it means the end of the field. CHAR defaults to 1 for the start position and to 0 for the end position.
Valid options are: MbdfhnRrV. They override the global options for this key.
Examples
Sort a file in ascending order:
sort {{path/to/file}}
Sort a file in descending order:
sort {{[-r|--reverse]}} {{path/to/file}}
Sort a file in case-insensitive way:
sort {{[-f|--ignore-case]}} {{path/to/file}}
Sort a file using numeric rather than alphabetic order:
sort {{[-n|--numeric-sort]}} {{path/to/file}}
Sort /etc/passwd by the 3rd field onward of each line numerically, using : as a field separator:
sort {{[-t|--field-separator]}} : {{[-k|--key]}} 3n /etc/passwd
As above, but when items in the 3rd field are equal, sort by the 4th field by numbers with exponents:
sort {{[-t|--field-separator]}} : {{[-k|--key]}} 3,3n {{[-k|--key]}} 4,4g /etc/passwd
Sort a file preserving only unique lines:
sort {{[-u|--unique]}} {{path/to/file}}
Sort a file, printing the output to the specified output file (can be used to sort a file in-place):
sort {{[-o|--output]}} {{path/to/output_file}} {{path/to/input_file}}
The examples are provided by the tldr-pages project under the CC BY 4.0 License.
Please note that, as uutils is a work in progress, some examples might fail.