My top20 most used commands

#dev, #linux, #me, #unix


Regular Bash config:

$ history | awk 'BEGIN {FS="[ \t]+|\\|"} {print $3}' | sort | uniq -c | sort -nr | head -n 5

My zsh config:

$ cat ~/.history | awk 'BEGIN {FS="[ \t]+|\\|"} {print $1}' | sort | uniq -c | sort -nr | head -n 5

I did not create the command from scratch, I just changed it to use in my case. See references for more details.

People LOVE sharing top-something artist, but here I came to share my top 20 most used terminal commands😍.

As you will see aws+sort command strips only the first part of the history. For example, if you have typed just git status and git add -p, there will be one entry for git with two executions.


The default output of bash’s history command is something like this:

$ history
    1  git status
    2  git add -p
    3  nvim .gitignore
    4  ssh remoteserver
    5  git status

If your output is like that use this command:

$ history | awk 'BEGIN {FS="[ \t]+|\\|"} {print $3}' | sort | uniq -c | sort -nr | head -n 5

The output will the list of commands in a ranking:

    165 git
    136 exit
     20 ssh
     19 nvim
      7 ls


My configuration for zsh is different. history does not return all the history but everything is stored in ~/.history.

If your $HISTFILE in zsh is like this:

$ head $HISTFILE
git status
git add -p
nvim .gitignore
ssh remoteserver
git status

You can use this version of awk+sort:

$ cat $HISTFILE | awk 'BEGIN {FS="[ \t]+|\\|"} {print $1}' | sort | uniq -c | sort -nr | head -n 5

That will output the same result.

My Top 20 commands ☺️

395 git
280 nvim
 81 ag
 67 ls
 66 mv
 63 find
 54 cat
 53 rm
 40 docker
 33 cp
 30 mkdir
 29 du
 26 tmux new
 22 youtube-dl
 19 docker-compose
 16 file
 15 less
 14 sudo
 11 which
 10 rmdir

I’m kinda surprised to know that I use basic stuff like cp, mkdir, rmdir.

Comment below what is your top commands ☺️.