What is an alias? It isn’t the ability to call yourself Thaddeus Jones when
your real name is Jedediah Curry. Instead, in a Linux-context it is the
ability to use a different name for a command, including the ability to pass
options and arguments to the command. In principle, aliases can be anything you want.
They are special names that you define to accomplish tasks. They aren’t
shell scripts, as a shell script is external to your
Like commands, aliases are started by typing them in. However, they are internal to the
Another major advantage is the ability to create new commands. You
can do this with shell scripts (which we will get into later), but the overhead
of creating a new process does not make it worthwhile for simple tasks. Aliases
can be created with multiple commands strung together. For example, I created an
alias, t, that shows me the time. Although the date command does that, all I
want to see is the time. So, I created an
When I type in t, I get the hours and minutes, just exactly the way I want. Granted one could create a shell script for this, but that would waste system resources as a new shell would need to get started each time.
Aliases can be defined in system-wide shell configuration file (e.g.
Be careful when
creating aliases or functions so that you don’t redefine existing commands.
Either you end up forgetting the
About an hour later, one of the other
engineers came into my cubicle with the same problem. He couldn’t come up with
anything either, which relieved me, so he decided that he needed to research the
issue. Well, he found the exact same message in the source code and it turned
out that this message appeared when a command could not run the
When should you use an alias, function or shell script? Well, if
there is something that can be done with a short shell script, then it can usually be
done with a function. However, there are things that are difficult to do with an
alias. One thing is making long, relatively complicated commands. Although you
can often do this with an
On some systems, you will find that they have already provide a number of
aliases for you. To see what aliases are currently configured, just run
As you can see there are many different ways you can use aliases.
Sometimes you may need to remove an alias. For example, when connecting across a network to a remote machine where the ls alias is defined as above. In many cases $LS_OPTIONS includes color encoding for differ types of files. This often makes the output difficult to read. So, to remove the command you would issue the command: