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
cc + Enter is much faster to type than
Aliases are defined in the
.bashrc file (typically in your user home directory).
A bash alias has the following structure:
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
We can just shorten that to
ll. Here’s the alias to do that:
alias ll="ls -lhaG"
Put that in your
.bashrc file and then open a new Terminal window or reload using:
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.