Alias Command

March 6, 2008

For those who are new to working with Unix, I want to take a moment to introduce aliases. The simplest means to think of an alias is as a text shortcut, used inside a Terminal window, to represent one or more commands. On second thought, maybe that isn’t the simplest means to describe an alias. Let me try again using an example…

I have an alias configured on my system with the name cls that is a shortcut for the command clear. Now, saving two keystokes is pretty trivial, however, given that you can assign an alias to commands that are much more involved, as well as use an alias to represent more than one command, all of a sudden it starts to make sense. Below is a list of the aliases that I am currently using:

alias ab='ant build.plugins'
alias ad='ant deploy.plugins'
alias cls='clear'
alias j='cd ~/Desktop/jive_clearspacex_standalone_1_6_0'
alias jivep='cd ~/Desktop/jive_clearspacex_standalone_1_6_0/plugins/plugins'
alias jj='./start-clearspace.sh'
alias jx='./stop-clearspace.sh'
alias ls='ls -al'
alias mjxtmp='cd /tmp/mojax.cache/localhost9180/source'
alias zd='sudo sh /etc/daily'
alias zm='sudo sh /etc/monthly'
alias zw='sudo sh /etc/weekly'

I generally find aliases helpful when I need to navigate to various directories and also when I need to run the same command(s ) repeatedly. You can see from the aliases above that I’ve been working on creating plugins for Clearspace, which involves starting/stopping an instance of Clearspace on my machine, moving between directories and running ant scripts to build and deploy. Using aliases save me a great deal of time and trouble typing in the same commands over and over.

You create aliases by editing .bash_profile in your home directory. Given that the filename begins with a “.” it is by default hidden by the operating system. You can configure Finder to show all files (including hidden/system files) using the Finder Preferences dialog:

You can learn more about working with aliases by accessing its manpage (type man alias in a Terminal) or viewing the alias command at the Linux Information Project.

The cls command mentioned earlier is more than simply a shortcut for clear, it’s also a throwback to my days working with DOS.

4 comments

Some that I personally like:

alias ll=’ls -lG’
alias la=’ls -AG’
alias l=’ls -FG’
alias ls=’ls -G’
alias grep=’grep –color=auto’
alias sha1sum=’openssl dgst -sha1′

I like colors, what can I do? :)

by Everson Santos Araujo on May 22, 2008 at 8:28 am. Reply #

Hello, I stumbled onto this page and have a question… if the results of these aliases weren’t what I was looking for, how would I delete them? Thanks in advance!

by Ron on Jun 23, 2008 at 3:51 pm. Reply #

You can remove any alias commands that you aren’t interested in. Simply delete those lines.

by john on Jun 23, 2008 at 5:30 pm. Reply #

Finally, a way to save my headaches for the missing “ll” command!

Thanks!

by Sean on Aug 21, 2008 at 8:24 pm. Reply #

Post a comment:

Required.

Required. Not published.