sort

sort #

对文件行进行排序。

text
sort lines of text files

Usage:
    sort [OPTION]... [FILE]...

Ordering options #

text
-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

-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

-r, --reverse
    reverse the result of comparisons

Other options #

text
-k, --key=KEYDEF
    sort via a key; KEYDEF gives location and type

-o, --output=FILE
    write result to FILE instead of standard output

-S, --buffer-size=SIZE
    use SIZE for main memory buffer

-t, --field-separator=SEP
    use SEP instead of non-blank to blank transition

--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

-z, --zero-terminated
    line delimiter is NUL, not newline

Examples #

bash
# Input (a.txt):
13 Apple
2 Origin
010 Banana

dictionary-order #

bash
sort a.txt
text
010 Banana
13 Apple
2 Origin

numeric-sort #

bash
sort -n a.txt
text
2 Origin
010 Banana
13 Apple

sort second key #

bash
sort -k 2 a.txt
text
13 Apple
010 Banana
2 Origin
2023年12月12日