Finding Which Commands I use all the Time

Mark C Allen
2 min readMar 18, 2023

I spend a lot of time in a terminal and extensively use tmux & vim to write code and manage systems. If you also spend a lot of time in a shell (sh, bash, zsh) you know that aliases can greatly help with productivity through the reduction in typing and typing mistakes.

In this article, I will show how I use your shell history to find out what commands I type all the time and then use this to create new aliases to help speed up my workflow.

Using Aliases

Most shells come with some already set, such as ll for ls -alF. To get a listing of all your current aliases run:

$ alias
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'

To get the details of the current directory without having to remember -alF run:

$ ll
-rw-r--r-- 1 mark staff 703 27 Oct 11:01 tsconfig.json
-rw-r--r-- 1 mark staff 149291 24 Mar 2022 tsconfig.tsbuildinfo
drwxr-xr-x 7 mark staff 224 2 Jun 10:03 utils/
-rw-r--r-- 1 mark staff 399679 24 Mar 2022 yarn-error.log
-rw-r--r-- 1 mark staff 422743 27 Oct 11:01 yarn.lock

You can add any others yourself to your shell init script such as .bash_profile. Here are a few I use:

alias dc='docker-compose'
alias ggraph='git log --oneline --graph'
alias gs='git status'
alias gversion='echo $(git describe --abbrev=0 --tags)-$(git log -1 --format=%h)'
alias k='kubectl'
alias tf='terraform'

I use docker-compose and terraform all the time so I have aliased them to dc and tf respectively. The gversion alias helps me know what the current version of my code will produce when I build and tag a docker image.

Finding New Aliases

Recently I was looking at my day-to-day workflow and how to speed up what I’m typing. I decided to look at my history and see what I typed a lot, and here is what I found.

Running the following in a terminal after a few hours shows:

  $ history | awk '{print $2}' | sort | uniq -c | sort -n 
27 czctl
28 curl
29 k9s
34 tmux
38 k
46 npm
58 more
68 ls
71 vi
84 yarn
91 cd
180 git

I’m already making good use of my alias for kubectl as k, but I seem to type git and yarn a lot, so I’ve added aliases for them.

alias g='git'
alias y='yarn'

Conclusion

Shell aliases can be a powerful tool for developers to customize and streamline their command-line workflow, increasing productivity and reducing errors. By looking at your history you can identify commands that are run frequently and create aliases for them.

--

--

Mark C Allen

DevOps Engineer and Evangelist | Experienced builder of SAAS startups | Engineer Manager, Leader and Coach | Creator of tools to make building software easier