3

This question already has an answer here:

Is there any way to find out top 10 most used commands in history? Here top 10 means commands which I have used most of the time i.e. the commands whose used count is more than others.

marked as duplicate by Takkat, Rinzwind, terdon, Community Oct 15 '15 at 12:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Define "top 10 most used commands". Just the commands or also considering the parameters? Note that history | sort can provide much of this, so you should narrow this down a little bit. – fedorqui Oct 15 '15 at 10:57
  • Found required answer in How can I make a list with most used commands in terminal?. But the answers given my question are more flexible and easy in terms of usability. – snoop Oct 15 '15 at 12:53
3

I have a little script myself to check what are the top N commands I have been using lately:

mylast () {
        re='^[0-9]+$'
        if ! [[ $1 =~ $re ]] ; then
           echo "error: $1 not a number" >&2
        else
           history | awk '{a[$2]++} END {for (i in a) print a[i], i}' | sort -rn | head -n $1
        fi
}

So by saying mylast 10 it shows the top 10.

This is done by going through the history and storing the 2nd field into in awk, so that the count can be tracked through an array.

Sample output:

$ mylast 5
248 git
107 python
93 grep
71 awk
52 less
4

One line:

history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl |  head -n10

Example output:

1  211  21.1%  ls
2  189  18.9%  sudo
3  58   5.8%   man
4  52   5.2%   cd
5  43   4.3%   ping
6  40   4%     apropos
7  34   3.4%   less
8  22   2.2%   cat
9  18   1.8%   which
10  18   1.8%   aspell

This site provides a little more information.

  • 3
    Hey, I wanted to apologize for my needlessly aggressive comment on your answer here. Upon reflection, I realized that the question was not very clear and it could indeed have been that the OP was attempting to do it as a different user. I still don't think they would have gotten those errors, but there was no reason to come down so hard on you. My apologies. – terdon Oct 15 '15 at 11:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.