Ask HN: Share your top 10 cli commands

We have last done this a few years ago. Below command will output the top 10 commands from your history file:

$ 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

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:

        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
        
    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:

         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
        
    EDIT2: The analysis may be more interesting if you check for piped commands as well, as I missed grep in the first list

        $ cat ~/.zhistory | grep grep | wc -l
        1098
        $ cat ~/.zhistory | grep sort | wc -l
        316

  •      1	1668  26.8426%    git
         2	723   11.635%     gst
         3	361   5.80946%    vim
         4	355   5.71291%    gd
         5	311   5.00483%    clear
         6	280   4.50595%    ls
         7	276   4.44158%    gco
         8	222   3.57258%    cd
         9	152   2.44609%    ga
        10	147   2.36563%    pip
    
    gst, gd, gco and ga are aliases for git status, diff, checkout and add respectively.

  •      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
    
    * (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.

    Edit:If anyone would like to have more granular view I wrote this oneliner sometime ago:

        history | cut -c8- | cut -d' ' -f1-2 | sort | uniq -c | sort -n
    
    It gives result like:

        # ... All other entries from history
        180 vim
        207 npm install
        212 gst
        220 git pull
        361 git commit
        537 git checkout

  • For OSX, the command is:

    $ 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

         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
    
    
    `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.

  •      1	1123  11.2311%   mpv
         2	631   6.31063%   sudo
         3	386   3.86039%   cd
         4	265   2.65027%   echo
         5	260   2.60026%   cat
         6	215   2.15022%   cowerd
         7	210   2.10021%   pacs
         8	173   1.73017%   tweet
         9	132   1.32013%   cowers
        10	128   1.28013%   pacman
    
    
    some handy shell functions https://paste.xinu.at/ocnBw/

  • This is in my macOS box. Pretty vanilla. I'm surprised `ls` didn't make it to the top10, probably due to auto-complete.

         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

  •      1	39  7.81563%   git
         2	35  7.01403%   rm
         3	33  6.61323%   cd
         4	28  5.61122%   wc
         5	28  5.61122%   make
         6	21  4.20842%   valgrind
         7	18  3.60721%   massif-visualizer
         8	16  3.20641%   cat
         9	13  2.60521%   vi
        10	12  2.40481%   ssh
    
    I've been fiddling with valgrind an unhealthy amount, just because I find it interesting.

  • My list:

         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
    
    '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:

         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

  • This doesn't take pipes into account...

         1	412  11.4191%    sudo
         2	301  8.34257%    curl
         3	197  5.46009%    cd
         4	182  5.04435%    cat
         5	163  4.51774%    git
         6	138  3.82483%    ll
         7	125  3.46452%    man
         8	116  3.21508%    npm
         9	79   2.18958%    echo
        10	74   2.051%      jq

  • The ks commands are aliases for kubectl to different clusters:

         1	147  29.4%  git
         2	37   7.4%   ks
         3	35   7%     ksdev
         4	32   6.4%   kprod
         5	20   4%     kslogs
         6	17   3.4%   kubectl
         7	8    1.6%   export
         8	6    1.2%   ssh
         9	6    1.2%   python
        10	5    1%     curl

  •      1	796  18.3664%    ls
         2	718  16.5667%    cd
         3	373  8.60637%    gradle
         4	342  7.89109%    git
         5	231  5.32995%    vim
         6	182  4.19935%    cat
         7	130  2.99954%    gulp
         8	124  2.8611%     .
         9	99   2.28426%    psql
        10	94   2.1689%     curl
    
    
    "." == alias to "cd .."

  • 1 169 23.4722% cd 2 122 16.9444% ls 3 76 10.5556% wp 4 62 8.61111% vim 5 47 6.52778% ee 6 28 3.88889% ping 7 27 3.75% bash 8 19 2.63889% chmod 9 15 2.08333% unzip 10 15 2.08333% mv

  •      1	1150  11.5012%   cd
         2	849   8.49085%   git
         3	749   7.49075%   gedit
         4	489   4.89049%   ls
         5	471   4.71047%   rm
         6	357   3.57036%   sudo
         7	311   3.11031%   ack
         8	279   2.79028%   cat
         9	262   2.62026%   find
        10	259   2.59026%   emacs

  •      1	1751  17.5118%   cd
         2	1542  15.4215%   git
         3	1273  12.7313%   ls
         4	501   5.0105%    touch
         5	330   3.30033%   ssh
         6	321   3.21032%   mkdir
         7	244   2.44024%   vagrant
         8	234   2.34023%   cat
         9	187   1.87019%   subl
        10	177   1.77018%   openstack

  •      1	905  9.05091%   yarn
         2	852  8.52085%   git
         3	658  6.58066%   ls
         4	504  5.0405%    sudo
         5	394  3.94039%   node
         6	380  3.80038%   cd
         7	332  3.32033%   npm
         8	254  2.54025%   rm
         9	191  1.91019%   vagrant
        10	185  1.85019%   nano

  • Mine:

         1	194  38.8%  git
         2	88   17.6%  curl
         3	62   12.4%  clear
         4	45   9%     npm
         5	17   3.4%   cd
         6	10   2%     rails
         7	10   2%     nvm
         8	10   2%     atom
         9	8    1.6%   ember
        10	7    1.4%   vi

  •      1	206  41.2%  git
         2	57   11.4%  ls
         3	43   8.6%   vim
         4	40   8%     cd
         5	31   6.2%   open
         6	27   5.4%   exit
         7	13   2.6%   grep
         8	12   2.4%   man
         9	10   2%     gforth
        10	6    1.2%   info

  • Mine:

         1	55  11%    cd
         2	53  10,6%  swift
         3	49  9,8%   ssh
         4	45  9%     ls
         5	30  6%     git
         6	23  4,6%   cf
         7	19  3,8%   vapor
         8	19  3,8%   say
         9	17  3,4%   sudo
        10	17  3,4%   ngrok

  •      1	97  19.4%  python
         2	88  17.6%  git
         3	35  7%     zappa
         4	34  6.8%   npm
         5	28  5.6%   ls
         6	28  5.6%   dig
         7	28  5.6%   cd
         8	26  5.2%   pip
         9	18  3.6%   cat
        10	15  3%     fab

  • undefined

  • 1 240 19.4647% git

    2 138 11.1922% vim

    3 121 9.81346% cd

    4 94 7.62368% ls

    5 50 4.05515% sF

    6 43 3.48743% exit

    7 40 3.24412% npm

    8 35 2.83861% tmux

    9 33 2.6764% node

    10 32 2.5953% ..

    sF is a function to search that formats output similar to sublime's text search

  •      1  21  43.75%    sudo
         2  8   16.6667%  cd
         3  5   10.4167%  iptables
         4  3   6.25%     ufw
         5  2   4.16667%  zabbix_agentd
         6  2   4.16667%  ls
         7  1   2.08333%  top
         8  1   2.08333%  tcpdump
         9  1   2.08333%  mc
        10  1   2.08333%  ifconfig