Ads 468x60px

List Your 15 Most Used Terminal Commands


Discovering most used Terminal commands with history
The history command is a useful way to find specific commands that have been used in the past, and it can also be used to discover what your personal most used commands are with the following command string:
history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head -15
The output strips any flags or parameters, providing only the root commands shown by the most commonly used. Example output may look like the following:
$ history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn |head -n 15
56 traceroute
35 nslookup
35 ssh
31 ls
28 curl
25 sftp
23 gcc
23 make
18 cd
18 cat
17 round
15 python
13 kill
13 clear
10 defaults
The number to the left indicates how many times the command has been used, per what is listed in bash history. Clearing bash history will obviously change those numbers, as will any adjustments to the length of commands stored in bash_history, and having it disabled completely will obviously cause the entire command to report back nothing.
If you’d rather see the most used complete commands, perhaps to make aliases or for another purpose, simplifying the command string by removing awk will accomplish that;
history | sort -rn | head
Leaving the -n flag off of ‘head’ will default to list 10 items, but any number can be applied by specifying it with -n.
These commands will work in OS X and Linux, and should work in other unix variations as well.