I just read this great article about Command Aliases in Unix shells. I felt so inspired by this post, I'm writing about how you can use aliases to speed up web development.
If you don't have a basic understanding of the UNIX shell, this article is not for you. If you are familiar with basic command such as: ls, cd, cp, mv, pwd you should be able to follow along.
Creating an alias helps you to run long commands with a few keystrokes. Hopefully my examples will make this clear. Wikipedia can explain this better than I can.
All the below examples are using Borne Again Shell (bash).
Starting with something simple: The ls command is probably the most used command on the Linux command line. While I was doing some basic server administration, Bruce Alderson suggested I set-up an ll alias. I was constantly using ls -l to view files, and could save precious keystrokes by creating an alias. This is how you create an alias for ll to run the command ls -l.
alias ll='ls -l'
Now whenever you type "ll" you will receive the same results as you would typing "ls -l". Here is the gotcha, it is very important to remember that an alias will only last for your current session. In order to keep the alias around permanently you have to add the alias to your .bashrc in your home directory.
How to set-up .bashrc In Ubuntu Pre 10.11
Note: Ubuntu 10.11 doesn't have this option commented out, so you can ignore this section if you are up-to-date with your install
placing a few aliases in .bashrc is okay, but we should really be organized. I place all of my aliases in .bash_aliases in my home directory. I didn't invent this, it is part of Ubuntu's documentation (lines 68 - 75 in default .bashrc). If your using Ubuntu you will want to un-comment the following code from your .bashrc file. If you are running a different distribution I recommend reading the documentation.
if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi
The above the alias file if it exists.
As I always share my code to help you learn, I've included my .bash_aliases file here. I'd love to get your feedback!
- You can remove an alias using unalias
- You can see available aliases by using alias
- You cannot use parameters with aliases(that is where bash scripts come in to play)