Counting with sort and uniq

1 · Benjamin Cane · Aug. 6, 2011, 2:20 a.m.
Here is another quick example of how to get a count of how many times a string appears. For my example I am going to use this output. $ cat /etc/passwd | cut -d: -f7 /bin/bash /bin/sh /bin/sh /bin/sh /bin/sync /bin/sh /bin/sh /bin/sh These are the shells of users on my system, what if I wanted to see what the most common shell was? $ cat /etc/passwd | cut -d: -f7 | sort | uniq -c | sort -nk1 1 /bin/sync 2 /usr/sbin/nologin 4 /bin/false 5 /bin/bash 20 /bin/sh In order to get this result I take ...