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 /home/dir1/dir2 $ alias ..='cd ..' $ .. $ pwd /home/dir1
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
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
~/.bash_aliases , or
~/.zshrc file, depending on your setup.