Shell aliases are commonly used to replace a command with a different or longer string. Some very common bash shell aliases are:
(taken from my Debian 5.0 .bashrc)
alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'
alias ls='ls --color=auto'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
As you can see, these aliases are assigning either an alternate command for a command + argument, or defining that a default command should work with extended options. Many of these are commented out by default, but you can edit your
.bashrc file and remove the comments if you like.
Now the question remains, if I have a command set to an alias, how can I run the command *without* the alias additions? There are two methods.
The system comes with a
unalias command. This is used to remove an alias definition you might have on a per-command basis. For example:
This command will undefine or remove the alias definitions for the ls command meaning, based on the definitions above, ls will no longer be run with the
--color=auto arguments. This change–the removal of the alias–will apply until you logout.
The second method allows you to run aliased commands in an unaliased fashion in a one-off manner. In other words, the removal of the alias definition only apply to that instance of the command, not for the remainder of your login session.
To use Method 2 of unaliasing a command simply prefix the command with a \:
This example achieves the same results as Method 1 but only temporarily–only for that instance of the ls command. The next time you run ls it’ll be back to its normal aliased settings. Method 2 allows you to temporarily disable an alias without needed to reassign it, or logout of your session.
In conclusion, aliases are very commonly used within the shell environment. You may even be using an aliased command and not even know it! The ability to unalias a command and run it with its native settings can be helpful in many situations.