DEV Community

Discussion on: What are your top ten command lines?

Collapse
leejarvis profile image
Lee Jarvis

I'm using zsh and this command didn't work well. I found this post which includes something nice! Here's mine:

~% history 1 | cat | 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
     1  300  25.5537%    ag
     2  95   8.09199%    g
     3  61   5.19591%    gl
     4  49   4.17376%    gb
     5  45   3.83305%    ls
     6  43   3.66269%    cm
     7  42   3.57751%    cd
     8  39   3.32198%    cat
     9  28   2.38501%    brew
    10  26   2.21465%    rm

ag is the command for the_silver_searcher -- I guess I search a lot!

Collapse
jappe999 profile image
jappe999

If you use zsh you can use the command zsh_stats.

Collapse
amejiarosario profile image
Adrian Mejia Author • Edited on

Nice! I didn't know about zsh_stats. It would have saved me some time tinkering with cut and uniq :P

$ zsh_stats                                                                      
     1  828  7.84165%     git
     2  691  6.54418%     gst
     3  533  5.04783%     gco
     4  469  4.44171%     cd
     5  439  4.15759%     ggpush
     6  367  3.47571%     gca
     7  363  3.43783%     grunt
     8  357  3.381%       ls
     9  299  2.83171%     npm
    10  291  2.75594%     make
    11  288  2.72753%     code
    12  248  2.34871%     open
    13  188  1.78047%     node
    14  188  1.78047%     hexo
    15  171  1.61947%     z
    16  156  1.47741%     brew
    17  145  1.37324%     ggpull
    18  141  1.33535%     ..
    19  138  1.30694%     cat
    20  136  1.288%       eos
Collapse
amejiarosario profile image
Adrian Mejia Author

Oh, that's weird it didn't work for you. I'm also using zsh. I'm just curious, what was not working with the original command?

Collapse
leejarvis profile image
Lee Jarvis

It just shows a bunch of commands with a count of 1 :-) The zsh_stats thing is very cool!