sort
- Sort lines of text files.
Syntax
1
| sort [OPTIONS] [FILE]...
|
Options
Common Option |
Description |
-f, --ignore-case |
fold lower case to upper case characters |
-n, --numeric-sort |
compare according to string numerical value |
-r, --reverse |
reverse the result of comparisons |
-k, –key=KEYDEF |
sort via a key; KEYDEF gives location and type |
-u, –unique |
remove redundent |
Examples
Sort lines in a file
sample file1
sample output
Sort lines in a file desc
find uniqe words and sort
Show processes sorted by user name
use -k 1
to sort the processes by first field, which is the user name.
1
| ps aux | sort -k 1 | head -n 10
|
Show processes sorted by CPU Usage desc
1
| ps aux | sort -r -k 4 -n | head -n 10
|
Reference