Temporarily Disable Aliases in Bash

By | 03/14/2009

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.

Method 1
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:

unalias ls

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.

Method 2
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 \:

\ls

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.

5 thoughts on “Temporarily Disable Aliases in Bash

  1. Michael

    Thanks for this great tip.
    I just wonder where I can find this info.
    In any of the documentation of man / info pages of the bash shell I could not find it.

    Is this info only available by digging in the source code of bash (i hope not )?

    Thanks in advance!

    1. admin Post author

      @Michael – the bash man page has more detailed information regarding aliases. man bash & then search for alias. The machine I did a quick search on did not have man pages for alias or unalias unfortunately.

      1. Michael

        Thanks for your reply.
        The funny thing is, I have done exactly what you mentioned. My machine has all the man (and info) pages installed and configured, but unfortunately nothing can be about about this great tip ‘\’… It is also true that Ubuntu standard not have installed the bash man en info page by default (at least by my Ubuntu installation long time ago). Anyway great blog! keep on doing !

Comments are closed.