Last Updated: February 25, 2016
·
614
· zhangtai

Basic usage of 'sort' command

du -s /usr/share/* | sort -nr | head

"-nr": number and reverse.

ls -l /usr/bin | sort -nr -k 5 | head

"-k": sort on the 5th column

sort --key=1,1 --key=2n distros.txt
sort -k 1,1 -k 2n distros.txt

sort start at field 1 and end at field 1, then column 2 by number

sort -k 3.7nbr -k 3.1nbr -k 3.4nbr distros.txt

"Fedora 10 11/25/2008"
sort on column 3 from 7th char, then 1st char, then 4th char.

sort -t ':' -k 7 /etc/passwd | head

"me:x:1001:1001:Myself,,,:/home/me:/bin/bash
root:x:0:0:root:/root:/bin/bash"

":" as separator