Create permanent terminal aliases
I am a lazy person and I don’t like to type the same commands over and over again so if you are like me this tutorial will come in handy.
The standard way to create an alias is for instance typing alias gl='git log'
but this alias will only exist until you close your terminal session so to create permanent alias we just need to do some actions.
- Let’s check which one are the most used commands in our terminal, you can use this command:
history | awk 'BEGIN {FS="[ \t]+|\\|"} {print $3}' | sort | uniq -c | sort -nr | head -n 20
2. Let’s create a file to save all our aliases vi ~/.bash_aliases
with this content as an example:
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias coi='code-insiders .'
alias vu='vagrant up'
alias vs='vagrant ssh'
alias vd='vagrant destroy -f'
3. Then we need to add a piece of code to load this file in our terminal configuration, depending on which shell we are using, for example vi ~/.bashrc or vi ~/.zshrc
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
NOTE: Don’t forget to reload your terminal =)