We have last done this a few years ago. Below command will output the top 10 commands from your history file:<p>$ 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<p>Here are my results.
1 293 58.6% git
2 30 6% sudo
3 30 6% npm
4 20 4% ls
5 14 2.8% scp
6 13 2.6% cd
7 9 1.8% ssh
8 9 1.8% history
9 8 1.6% rm
10 5 1% pwd
Had to adjust on my zsh shell:<p><pre><code> cat ~/.zhistory | cut -d";" -f2 | awk '{CMD[$1]++;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
1 1681 15.2472% git
2 964 8.74376% yarn
3 921 8.35374% cat
4 755 6.84807% docker
5 628 5.69615% brew
6 515 4.6712% cd
7 372 3.37415% curl
8 366 3.31973% npm
9 298 2.70295% trash
10 270 2.44898% find
</code></pre>
EDIT: trash is is like rm, but moves to system trash. From the reast you see that I mainly work in the JS ecosystem. If I add the second parameter, things get more interesting, and docker pops up:<p><pre><code> 1 645 5.84928% git checkout
2 324 2.93824% yarn add
3 221 2.00417% brew cask
4 176 1.59608%
5 161 1.46005% find .
6 157 1.42378% yarn upgrade
7 136 1.23334% docker run
8 125 1.13358% curl -s
9 124 1.12451% docker image
10 121 1.09731% yarn remove
</code></pre>
EDIT2: The analysis may be more interesting if you check for piped commands as well, as I missed grep in the first list<p><pre><code> $ cat ~/.zhistory | grep grep | wc -l
1098
$ cat ~/.zhistory | grep sort | wc -l
316</code></pre>
<p><pre><code> 1 2258 22.5823% git
2 594 5.94059% npm
3 539 5.39054% cd
4 366 3.66037% ls
5 360 3.60036% vim
6 344 3.44034% cat
7 316 3.16032% rm
8 287 2.87029% mix
9 255 2.55026% nr
10 216 2.16022% X_IP=0.0.0.0*
11 213 2.13021% gst
</code></pre>
* (Omitted) It's not a command but environment variable followed by a command. I could probably alias it, but it is pretty unique and so easy to find with ^R in zsh.<p>Edit:If anyone would like to have more granular view I wrote this oneliner sometime ago:<p><pre><code> history | cut -c8- | cut -d' ' -f1-2 | sort | uniq -c | sort -n
</code></pre>
It gives result like:<p><pre><code> # ... All other entries from history
180 vim
207 npm install
212 gst
220 git pull
361 git commit
537 git checkout</code></pre>
For OSX, the command is:<p>$ history | awk '{CMD[$5]++;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<p><pre><code> 1 104 20.8% ls
2 72 14.4% cd
3 49 9.8% pip
4 25 5% a
5 21 4.2% j
6 19 3.8% z
7 19 3.8% vim
8 19 3.8% git
9 19 3.8% cat
10 12 2.4% sba
11 12 2.4% gs
13 8 1.6% ga
14 7 1.4% p
15 5 1% sof
</code></pre>
`a` is an alias for ag, `j` is an alias for `autojump`, `sba` is an alias for `source env/bin/activate`. `gs` is git status, `ga` is git add, `p` is python, `sof` is soundscrape -of, `z` is zappa.
This is in my macOS box. Pretty vanilla. I'm surprised `ls` didn't make it to the top10, probably due to auto-complete.<p><pre><code> 1 1855 18.5519% git
2 851 8.51085% cd
3 493 4.93049% rm
4 414 4.14041% brew
5 376 3.76038% find
6 373 3.73037% vi
7 369 3.69037% docker
8 338 3.38034% cat
9 238 2.38024% vim
10 237 2.37024% ag</code></pre>
My list:<p><pre><code> 1 565 14,3437% vim
2 513 13,0236% cd
3 468 11,8812% git
4 280 7,1084% yarn
5 147 3,73191% npm
6 104 2,64026% gulp
7 95 2,41178% up
8 87 2,20868% rm
9 82 2,08175% docker
10 79 2,00559% la
</code></pre>
'up' is an alias for 'cd ..' and 'la' is an alias for 'ls -la'.
I expected `ls`, and `cd` to be top, and they were:<p><pre><code> 1 34393 18.2057% ls
2 29496 15.6135% cd
3 22794 12.0659% git
4 21305 11.2777% ssh
5 6181 3.27188% make
6 5183 2.74359% less
7 4616 2.44345% cat
8 4379 2.318% vi
9 3474 1.83894% rm
10 2892 1.53086% ping</code></pre>