Nine Circles of Shell

Unix Aliases

Unix Aliases

20 March, 2020

Here's a quick and dirty guide to aliases in Unix.

Aliases provide an alternative way to invoke shell commands. Aliases are especially useful for abbreviating oft used commands into simpler invocations. For example, an alias could be set like alias ls='ls -p'. Now when you use ls, you're actually calling ls -p, but you don't have to add the -p argument each time.

Setting up an alias

Set an alias as shown above by using the alias command. The basic syntax is to call the alias command followed by what you want to type to invoke the alias and then the alias itself after an '=' sign and within single quotes along with any options.

alias grep='grep --color=auto'

If you want to see what aliases you have set, simply type alias into your shell and it will list the aliases that have been set.

$ alias
alias ali='vim ~/.bash_profile'
alias dev='cd ~/Documents/Developer; pwd'
alias imgcat='~/.iterm2/imgcat'
alias it2dl='~/.iterm2/it2dl'
alias lbin='cd /usr/local/bin; pwd'
alias ls='ls -p'
alias slcc='cd ~/Documents/SLCC; pwd'
alias srcb='source ~/.bash_profile; echo "reset bash profile"'

Editing your alias file

If you wanted to remove or edit an alias, you need to actually edit the file that they live in. This file differs across shells, but here is a list of common shells and what the name of the file you need to edit.

  • bash: ~/.bashrc
  • zsh: ~/.zshrc
  • MacOS: ~/.bash_profile

The astute reader my notice that I have an alias set up to quickly edit this file. alias ali='vim ~/.bash_profile'. Setting up something like this is helpful if you're like me and immediately forget everything you just read!