DEV Community

Serhat Teker
Serhat Teker

Posted on • Originally published at tech.serhatteker.com on

Most Used Commands in Your Shell

I don't remember where I encountered shell history (bash, zsh etc.), commands but I'd like to share them with you as well:

$ history | awk '{print $2}' | sort | uniq -c | sort -nr | head -10
Enter fullscreen mode Exit fullscreen mode

What these commands do, let's look at them each:

  • The awk '{print $2}' prints first fields from the history
  • The famous | transfers or make one command's output to the input of the next.
  • The sort orders all lines alphabetically
  • The uniq -c removes the duplicate lines (typed commands) and count them
  • The sort -nr displays the commands in reverse order by the count number
  • And the head -10 displays only first 10 commands.

And the result will be like:

   1157 vi
   1032 cd
   863 nvim
   539 la
   384 git
   345 rm
   293 sudo
   264 make
   241 tmux
   240 python
Enter fullscreen mode Exit fullscreen mode

So it means that I am using vi command most: 1157 times.

There are some other alternatives for shell history command:

#1

History with percentage detail:

$ 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

Enter fullscreen mode Exit fullscreen mode

The output will be like:

     1  1157  11.5296%     vi
     2  1032  10.284%      cd
     3  863   8.5999%      nvim
     4  539   5.3712%      la
     5  384   3.82661%     git
     6  345   3.43797%     rm
     7  293   2.91978%     sudo
     8  264   2.63079%     make
     9  241   2.40159%     tmux
    10  240   2.39163%     python
Enter fullscreen mode Exit fullscreen mode

#2

History with bar graph:

$ history | tr -s ' ' | cut -d ' ' -f3 | sort | uniq -c | sort -n | tail | perl -lane 'print $F[1], "\t", $F[0], " ", "▄" x ($F[0] / 12)'
Enter fullscreen mode Exit fullscreen mode

The output:

tmux    239 ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
python  240 ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
make    263 ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
sudo    293 ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
rm  345 ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
git 383 ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
la  539 ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
nvim    859 ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
cd  1028 ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
vi  1157 ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
Enter fullscreen mode Exit fullscreen mode

All done!

Top comments (2)

Collapse
 
nicklediet profile image
Nicholas Lediet

Thought I would share mine!

composer        20 ▄
drush   21 ▄
terminus        24 ▄▄
sudo    26 ▄▄
cat     28 ▄▄
d       46 ▄▄▄
vim     63 ▄▄▄▄▄
ll      69 ▄▄▄▄▄
cd      72 ▄▄▄▄▄▄
git     155 ▄▄▄▄▄▄▄▄▄▄▄▄
Collapse
 
serhatteker profile image
Serhat Teker

Thank you!