sort sorts lines of text files. sort is especially useful in conjunction with uniq (because uniq needs the input lines to be sorted). sort | uniq can nowadays usually be abbreviavated with sort -u -b | --ignore-leading-blanks | ignore leading blanks | |
-d | --dictionary-order | consider only blanks and alphanumeric characters | |
-f | --ignore-case | fold lower case to upper case characters | |
-g | --general-numeric-sort | compare according to general numerical value | |
-i | --ignore-nonprinting | consider only printable characters | |
-M | --month-sort | compare (unknown) < 'JAN' < ... < 'DEC' | |
-h | --human-numeric-sort | compare human readable numbers (e.g., 2K 1G) | |
-n | --numeric-sort | compare according to string numerical value | |
-R | --random-sort | Shuffle, but group identical keys. See also shuf(1) | |
--random-source | =FILE | get random bytes from FILE | |
-r | --reverse | reverse the result of comparisons | |
--sort | =WORD | sort according to WORD. General-numeric -g, human-numeric -h, month -M, numeric -n, random -R, version -V | |
-V | --version-sort | natural sort of (version) numbers within text. Compare ls -v |
--batch-size | =NMERGE | merge at most NMERGE inputs at once; for more use temp files | |
-c | --check | =diagnose-first | Check for sorted input; do not sort |
-C | --check=quiet | Like -c, but do not report first bad line (compare --check=silent) | |
--compress-program | =PROG | compress temporaries with PROG; decompress them with PROG -d | |
--debug | annotate the part of the line used to sort, and warn about questionable usage to stderr | ||
--files0-from | =F | Read input from the files specified by NUL-terminated names in file F; If F is - then read names from stdin. | |
-k | --key | =KEYDEF | Sort via a key; KEYDEF gives location and type |
-m | --merge | merge already sorted files; do not sort | |
-o | --output | =FILE | write result to FILE instead of stdout |
-s | --stable | stabilize sort by disabling last-resort comparison | |
-S | --buffer-size | =SIZE | use SIZE for main memory buffer |
-t | --field-separator | =SEP | use SEP instead of non-blank to blank transition |
-T | --temporary-directory | =DIR | use DIR for temporaries, not $TMPDIR or /tmp; multiple options specify multiple directories |
--parallel | =N | change the number of sorts run concurrently to N | |
-u | --unique | with -c, check for strict ordering; without -c, output only the first of an equal run. Compare with uniq | |
-z | --zero-terminated | line delimiter is NUL, not newline | |
--help | |||
--version |
-o flag specifies an output file name for the sorted file. cat > to-be-sorted <<"EOF" one two three four five EOF sort to-be-sorted -o to-be-sorted cat to-be-sorted
-n, sort sorts values numerically rather than alphabetically. sort considers 123 to be smaller than 89. -h causes the sorted values to be interpreted as human readable, for example 1.89G or 815M. ls also has an -h flag which reports file sizes human readable. ls with the -h flag can be piped in sort with the -h flag to show a directory's largest files with file sizes human readable. -k allows to define a start and optional stop position: -k startpos[,stoppos] startpos and stoppos is F[.C][OPTS]: F | Field number |
C | Character pos in the field |
OPTS | a series of single-letter ordering options |
LC_ALL to C. --debug option. shuf randomly permutates the input lines.