Linux "sort" Command Line Options and Examples
sort lines of text files

Write sorted concatenation of all FILE(s) to standard output. With no FILE, or when FILE is -, read standard input. Mandatory arguments to long options are mandatory for short options too.


Usage:

sort [OPTION]... [FILE]...
    sort [OPTION]... --files0-from=F






Command Line Options:

-b
ignore leading blanks
sort -b ...
-d
consider only blanks and alphanumeric characters
sort -d ...
-f
fold lower case to upper case characters
sort -f ...
-g
compare according to general numerical value
sort -g ...
-i
consider only printable characters
sort -i ...
-M
compare (unknown) < 'JAN' < ... < 'DEC'
sort -M ...
-h
compare human readable numbers (e.g., 2K 1G)
sort -h ...
-n
compare according to string numerical value
sort -n ...
-R
shuffle, but group identical keys. See shuf(1)
sort -R ...
--random-source
get random bytes from FILE
sort --random-source ...
-r
reverse the result of comparisons
sort -r ...
--sort
sort according to WORD: general-numeric -g, human-numeric -h, month -M, numeric -n, random -R, version
sort --sort ...
-V
natural sort of (version) numbers within textOther options:
sort -V ...
--batch-size
merge at most NMERGE inputs at once; for more use temp files
sort --batch-size ...
-c
check for sorted input; do not sort
sort -c ...
-C
like -c, but do not report first bad line
sort -C ...
--compress-program
compress temporaries with PROG; decompress them with PROG -d
sort --compress-program ...
--debug
annotate the part of the line used to sort, and warn about questionable usage to stderr
sort --debug ...
--files0-from
read input from the files specified by NUL-terminated names in file F; If F is - then read names fromstandard input
sort --files0-from ...
-k
sort via a key; KEYDEF gives location and type
sort -k ...
-m
merge already sorted files; do not sort
sort -m ...
-o
write result to FILE instead of standard output
sort -o ...
-s
stabilize sort by disabling last-resort comparison
sort -s ...
-S
use SIZE for main memory buffer
sort -S ...
-t
use SEP instead of non-blank to blank transition
sort -t ...
-T
use DIR for temporaries, not $TMPDIR or /tmp; multiple options specify multiple directories
sort -T ...
--parallel
change the number of sorts run concurrently to N
sort --parallel ...
-u
with -c, check for strict ordering; without -c, output only the first of an equal run
sort -u ...
-z
line delimiter is NUL, not newline
sort -z ...
--help
display this help and exit
sort --help ...
--version
output version information and exitKEYDEF is F[.C][OPTS][,F[.C][OPTS]] for start and stop position, where F is a field number and C a characterposition in the field; both are origin 1, and the stop position defaults to the line's end. If neither -t nor
sort --version ...