Quick Tip: Using Aliases for Good

In Bash, the default Unix shell on most Linux systems, you can save yourself a little bit of time and typing effort by using the alias command to create some shortcuts. Typically, Linux admins set up some custom aliases for tasks they do repeatedly, or take a long time to type in.

These commands also apply to alternative shells as well, like zsh.

Let’s say you want to make the task of using cd to move up one directory a little easier.

Instead of typing cd .. every time, you can create an alias.

$ pwd
$ alias ..='cd ..'
$ ..
$ pwd

There’s enormous flexibility and endless creative opportunities here, and no “best” way to go about creating aliases, especially if you’re a lone developer/administrator. Obviously, if you’re working with a team, you’ll want to make sure you’re all on the same page.

Here’s some other possibilities:

$ alias lt='ls -ltFh'      # long list, sorted by date, show type, human readable
$ alias help='man'     # for those who forget about man pages
$ alias ...='cd ...'       # to move up two directory levels
$ alias gs='git status'    # one of many git-related possibilities
$ alias please='sudo -E'   # for the polite sudoers

The contributors behind oh-my-zsh have a bunch of pre-built aliases for you to peruse.

If you want to ensure these aliases are persistent, in that they will you’ll be able to use them after a reboot, you should edit your ~/.bashrc , ~/.bash_aliases , or ~/.zshrc file, depending on your setup.