Creating Aliases with .bashrc

bashrc

Using Kubuntu 13.10 x64 and OS X 10.9.

Want to be able to launch several commands at once or at least shorten some already esiting commands? We can do that by creating aliases. I like to use nano, but any text editor will do.

[OPTIONAL] Install nano

Ubuntu

sudo apt-get install nano

OS X installs nano with Xcode.

Here we're editing .bashrc with nano, but keep in mind it won't be pre-installed on all systems.

Edit .bashrc or .bash_profile

Ubuntu. Edit/create .bashrc.

nano .bashrc

OS X. Edit/create .bash_profile.

nano .bashrc

Go to the bottom of the file and create commands of this form.

alias **ALIAS_NAME**='**COMMAND#1** ; **COMMAND#2**; ... ; **COMMAND#n**'

Save (crtl+o) and exit (ctrl+x). You'll have to close and reopen the terminal window for this to take effect, but afterwards all those commands will be available just by typing that alias!

[EXAMPLE] Update your Ghost blog on OpenShift. This is useful if you came over from my Ghost/OpenShift post. Add the following to your .bashrc so updating your site is as easy as typing rhc-up! Please make sure to run it from your ghost app directory.

alias rhc-up = 'clear ; git add --all . ; git commit -m '$(date +%Y-%m-%d)@$(date '+%H:%M')' ; git push ; rhc app restart'

The command has been tweaked to name all commits with the date and time. The entire update and app restart will take up to five minutes, for which time your site will be offline.

[EXAMPLE] Run all available updates by typing 'update'. Add this to the end of your .bashrc file.

alias update = 'sudo apt-get update ; sudo apt-get upgrade -y ; sudo apt-get dist-upgrade -y'


That's it, so enjoy! :D

comments powered by Disqus

Recent Posts