Using command aliases in Ubuntu 13.04
I’ve been spending a lot of time working on a project lately where I found myself having to use some commands over and over. It’s gotten to a point where I decided to create some scripts to execute the commands for me. But then even calling the scripts started to become tedious that I created short bash command aliases to execute them instead.
If you’re using the bash shell, all you have to do is create a .bash_aliases file in your home directory to create these command aliases. Inside the .bash_aliases file, put your entries in this format:
alias cmd_alias=’longer command or script to execute’
Once you’re done making your changes, simply run source .bash_aliases to apply them.
For example, I’m working on a project called GlucoseTracker, which is a Django app inside a virtualenv. I created a simple script to activate the virtual environment and change my working directory to where my project’s main files are located, where I can then start the web server and run a bunch of other commands I might need such as git interactions.
I created a command alias called dgt for it, short for ‘develop glucosetracker’ as I run this command many times a day and the time savings add up quickly.
I have a few other aliases there as well for things I use often, such as connecting to an EC2 instance on AWS that I use for testing. I like to organize my files a certain way and having to type in the path for my public key to SSH to my server every time I connect could be painful.
One thing I would avoid using aliases for, though, is making common Linux commands shorter, as you might get into a habit of typing it in and confuse yourself when you’re logged in to another machine.