Getting started with .bash_profile

22 04 2011

If you are new to the UNIX-like command line interface (CLI) and you think you are going to spend more and more time there, creating a .bash_profile file is something to consider. You may have already used the Terminal for quite some time and never used your .bash_profile.

The .bash_profile is a hidden plain text file that resides inside your home directory (~/). Keep in mind that your home directory (~/) and your root directory (/) are not the same thing. Stay inside your home directory and its subdirectories while we work on the .bash_profile. This file is like a settings file. It keeps instructions that are used when setting up your environment whenever a new shell (Terminal window or tab) is opened. These instructions can specify settings and aliases. I get the most use out of aliases.

I am a web developer, so I spend a great deal of my time in the command line. I actually came to prefer it over the GUI for work-related stuff. By creating aliases, or shortcuts, for my Terminal, I save myself a bit of time and effort when I try to accomplish common tasks.

A good example is getting to where my work projects are stored. I build WordPress sites, primarily and I run MAMP on my MacBook at work so I can build the site on my laptop before I push the code up to our development server. (MAMP = Mac Apache MySQL PHP.) Here’s the file address to a given project’s location:


Obviously, this can be a bit inconvenient, so I created an alias in my .bash_profile to take me to the htdocs folder and list its contents.

alias mamp="cd /Applications/MAMP/htdocs/; ls -l;"

After running “source ~/.bash_profile” or opening a new shell, I can just type “mamp” and I am taken to the htdocs folder and its contents are listed for me. Once you get the hang of this, it can really help you more out of the Terminal.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: