Archive for the ‘Tutorial’ Category

Make .bashrc Work for You with Aliases

Sunday, June 7th, 2009

fts-unix-frontQuick disclaimer, I’m no command line guru, but I am a huge fan of anything that helps me do my job faster, so I decided to load up someĀ aliases in .bashrc this morning. A perfectly good Sunday morning activity.

I quickly ran in to a problem, though. My aliases weren’t working. The only way I could get them to work was to run source .bashrc. Logging out of Terminal didn’t do me any good, and setting a Terminal startup preference to run source .bashrc only worked for the first new window. Drag. So, to the Google Machine I went.

A simple search for Terminal doesn’t recognize .bashrc returned a helpful thread from macosxhints.com. A quick look at all the files in my home directory revealed no .bash_profile file. Aha! All I needed to do was create that file then add if [ -f ~/.bashrc ]; then . ~/.bashrc; fi and voila, problem solved. Update: After I tried to fire up a Rails project I realized that I should have modified .bash_login on my machine. The mix up caused a little problem where my version of RubyGems wasn’t being found. If you have .bash_login, add the aforementioned line there.

Now I can alias to my hearts content. I like to alias my ssh commands and other common directories that I frequently work from. Below are a few examples of popular aliases as well as how to use alias.

How to:

alias newcommand=”commandToBeExecuted”

Examples:

alias ll=”ls -ltr” #lists, in long form, non-hidden files in reverse order according to most recently modified

alias lf=”ls -F” #returns a file listing with / at the end of directories and @ at the end of symbolic links

alias l=”ls -al” #lists, in long form, all files, even hidden dot files, in long form

alias rm=”rm -i” #this command will prompt you when you attempt to remove a file

As I mentioned, I like to create aliases for quick access to directories I frequent. For example, when I fire up GoComics locally I use the following alias:

alias gc=”cd ~/path/to/gocomics/” #this gets me there no matter where I am in the files.

For more on alias check out http://www.itworld.com/operating-systems/59407/handy-dandy-aliases.