Using bash aliases as shortcuts to common tasks

I wish I’d discovered this about three years ago when I first started learning the bash command line – it would have saved a lot of remembering paths and typing them.

Bash provides the alias function which allows you to save commonly typed commands with a shortcut reference so you don’t have to type the whole command. This will be particularly useful for me when I log into my VPS as root and need to change directory to my development site (something I do several times daily).

Normally I might log in and type a command like this:

# cd /home/myDomain/myDevProjectFolder

.. which takes me a few seconds even when using the tab key to automatically complete paths. Now I can just type:

# mydev

and bash will run the alias I set for this folder, changing directory to dev folder.

How to configure it?

Edit your .bash_profile file

# vi ~/.bash_profile

Add the following line

alias mydev="cd /home/myDomain/myDevProjectFolder"

Save the file and reload the bash profile:

# source ~/.bash_profile

Now the alias should be active. How cool is that?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>