Reference: sort
sort
sort [options]
[files]-b-c-d-f-i-
Ignore nonprinting characters (those outside ASCII range 040-176).
-kfieldspec-
Specify significance of input fields for sorting. See the fuller description below. Solaris only.
-m-M-n-
-ofile-r-
Reverse the order of the sort.
-tc-
Fields are separated with c (default is any whitespace).
-Tdir-u-y[kmem]-
-zrecsz+n [-m]-
Skip n fields before sorting, and sort up to field position m. If m is missing, sort to end of line. Positions take the form a.b, which means character b of field a. If .b is missing, sort at the first character of the field. Counting starts at zero. Solaris allows fields to have optional trailing modifiers, as in the
-koption.
Field Specifications for -k
A fieldspec has the form
fieldstart[type][,fieldend[type]].
- fieldstart
- fieldend
- type
-
Examples
wc -l * | sort -rn
Alphabetize a list of words, remove duplicates, and print the frequency of each word:
sort -fd wordlist | uniq -c
Sort the password file numerically by the third field (user ID):
sort +2n -t: /etc/passwd
cd /home; du -sk * | sort -nr | head -20





