The Mijingo Blog

Latest news, updates, free tutorials, and more from Mijingo.

Creating Bash Aliases

by Ryan Irelan

Bash aliases allow you to set a shortcut command for a longer command. For example, you could set the command cc to be a shortcut for the clear command. cc + Enter is much faster to type than clear.

Aliases are defined in the .bash_profile or .bashrc file (typically in your user home directory).

A bash alias has the following structure:

alias [alias_name]="[command_to_alias]"

A new alias always starts on a new line with the alias keyword. You define the shortcut command you want to use with the alias name, followed by an equal sign. In quote, you type the full command you want to run.

A popular example is customizing the ls command for listing directories and files. Instead of typing out

ls -lhaG

We can just shorten that to ll. Here’s the alias to do that:

alias ll="ls -lhaG"

Put that in your .bash_profile or .bashrc file and then open a new Terminal window or reload using:

source ~/.bash_profile

Now, type ll and you should see the full command run.

Here’s a video excerpt from our Command Line Fundamentals how-to video that covers the basic of bash aliases.

Want to learn the basics of navigating around the command line? Watch our Command Line Fundamentals course.

Filed Under: Command Line, Free Tutorials, OS X