sort command in UNIX
sort [OPTION]... [FILE]...sort [OPTION]... --files0-from=FIntroduction
Section titled “Introduction”Write sorted concatenation of all FILE(s) to standard output.
With no FILE (or when FILE is -), read standard input, just like nano does.
Options
Section titled “Options”The most useful options are:
-f,--ignore-case: fold lower case to upper case characters-i,--ignore-nonprinting: consider only printable characters-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)--files0-from=F: read input from the files specified byNUL-terminated names in fileF; IfFis-then read names from standard input-o,--output=FILE: write result toFILEinstead of standard output--parallel=N: change the number of sorts run concurrently toN
Examples
Section titled “Examples”Given to-sort.txt file:
20MB500kB1TB890 bitsLet’s try some sort options:
sort to-sort.txt1TB20MB500kB890 bits
# compare human readable numbers (e.g., 2K 1G)# sort -h to-sort.txtsort --sort=human-numeric to-sort.txt890 bits500kB20MB1TBGiven to-sort.txt file:
22 cats5 clocks10 dogs80 carsLet’s sort it:
sort to-sort.txt10 dogs22 cats5 clocks80 cars
# compare according to string numerical value# sort --sort=numeric to-sort.txtsort -n to-sort.txt5 clocks10 dogs22 cats80 cars
sort -n to-sort.txt --debugsort: using ‘en_US.UTF-8’ sorting rules5 clocks_________10 dogs_________22 cats_________80 cars_________
sort -n --output=sorted-file.txt to-sort.txtcat sorted-file.txt# ...Quotes
Section titled “Quotes”Manual reference: