Moncef Belyamani

Coding, productivity, and Mac automation tutorials for beginners and beyond.

Create Aliases in .bash_profile to Assign Shortcuts for Common Terminal Commands

If you’re in Terminal all the time, and you regularly type long commands, you can get back those precious moments of your life by creating aliases for those commands in your .bash_profile, which is a file in your Home directory that sets up and customizes your Terminal session.

Let’s say you often browse to a directory that requires a lot of typing, such as:

1
$ cd ~/Dropbox/projects/octopress/source/_posts

You can create a shortcut by adding the following line to .bash_profile:

1
alias cdp="cd ~/Dropbox/projects/octopress/source/_posts"

Save the file, then either quit and relaunch Terminal, or refresh the changes by typing:

1
$ source ~/.bash_profile

From now on, to go to your Octopress posts directory, you can use this shortcut:

1
$ cdp

Another useful alias you can create is for opening files with your favorite text editor. In my case, it’s Sublime Text 2, which already comes with an OS X Command Line tool called subl, but I find that typing subl is awkward. I’d rather type slt, so I created the following alias:

1
alias slt='open -a "Sublime Text 2"'

This allows me to use the following command to open a file with Sublime Text 2:

1
$ slt ~/.bash_profile

I hope you found this tip useful, and if you have any bash tricks of your own, I’d love to hear about them.