# Which command do I use the most?

After waking to a ringing phone, I was attempting to fall back asleep. As I drifted, I wondered which command I used the most? I thought it a neat exercise, so I found out.

As I type this, I suspect it is ls. Which is second and third should be interesting.

I gathered up .zsh_history and .bash_history files from 5 different machines I work on a fair bit and put them in a pile, erm, directory.

$cat bash_history? < big_bash_history$ wc -l big_bash_history
2897 big_bash_history
$sed -e 's/^.*;//g' zsh_history? <big_zsh_history$ wc -l big_zsh_history
31188 big_zsh_history

Wow! 35 thousand commands. Wait… There’s a snafu in there. SUDO. Hmm….

$awk '{print$1}' big_zsh_history|grep sudo |wc -l
2045
$awk '{print$1}' big_bash_history|grep sudo |wc -l
887

Okay. I’ve got some numbers around that…Let’s see about stripping those and get the underlying command.

$sed -r -e '/sudo -i/d' -e 's/sudo //g' big_bash_history big_zsh_history|awk '{print$1}'|while read CMD;do basename "$CMD"; done |sort |uniq -c |sort -rn |head -20 4571 cd 3845 ls 2884 vi 2436 git 1719 ssh 1195 cat 1032 grep 928 rm 797 ansible-playbook 659 mv 619 pass 619 cp 443 python 438 scp 394 apt-get 373 salt 372 mkdir 339 more 297 find 291 done Okay. No surprises in the top five. ansible-playbook surprised me. Didn’t realize I entered that so much. There were more points of interest after the first twenty, but I won’t post those. Interesting done showed up in the top twenty. Thinking about this, it makes sense, as the first command is usually input to while, ie: ls | while read FILE; do echo$FILE; done

No if or fi in the top twenty. How about that.

Actually, thinking about this more, there are probably many more missing commands that were piped into another or, say rm used in an exec for find.