Ranking of the most frequently used commands
2011-01-31
334 words
2 mins read
Lets take a quick look at how to get the most frequently used commands on you shell. So what we need to do is this:
1
|
So, how did we arrive at this and will this always work? No it might not always work. A typical example is where HISTTIMEFORMAT variable is set. In that case, if you check history, you will see that after the number column we have time and date in the specified format, in which case, you will get wrong information from the above command. Anyways, forgetting these special cases, lets go to how we got this command:
1
|
will give us list of all the commands that we have used and are in history. But this will also give commands like “history|more” as one command as this does not have any space. So, we eliminate whatever is there after the “|” with awk command
1
|
or
1
|
and now to get all the counts, we need to sort and then count unique occurances:
1
|
Time for pretty display and make the display more readable to users:
add sort -n to sort with first column treated as number and then tail to display only few lines and then sort -nr to display in reverse order so that the top entry is the most used one 🙂
Related articles
- imabonehead: Linuxaria 6 Tricks with awk : Linuxaria (linuxaria.com)
- Poor mans dmenu benchmark (dieter.plaetinck.be)
- How do I use awk inside my Automator workflow? (ask.metafilter.com)
Related Articles:
- 2010/12/23 Bash Script Beautifier
- 2010/06/25 Magic space on the current command line
- 2010/06/08 Determine what process is listening on a port on Solaris, without lsof
- 2010/02/04 Splitting strings with IFS
- 2011/01/25 shopt causes bash completion to stop working.
Authored By Amit Agarwal
Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.