Bash Shell Temporarily Disable an Alias

I have couple of shell aliases defined in ~/.bashrc file. How do I temporarily remove (disable) a shell alias and call the core command directly without using unalias command under a bash shell on a Linux or Unix-like systems?

An alias command enables a replacement of a word with another string. It is mainly used for abbreviating a system command, or for adding default arguments to a regularly used command. [donotprint]
Tutorial details
DifficultyEasy (rss)
Root privilegesNo
RequirementsNone
Time2m
[/donotprint]It is also useful for creating your own commands on a Linux, OS X, FreeBSD, OpenBSD, Ubuntu/Debian/Red hat/CentOS/Fedora and Unix-like operating systems.

ADVERTISEMENTS

How to display currently defined aliases

Type the following command:
$ alias
Sample outputs:
Bash Shell Temporarily Disable an Alias

How to create an alias

Create an alias called c for the commonly used clear command, which clear the screen:
$ alias c='clear'
Then, to clear the screen, instead of typing clear, the user would only have to type the letter c and press the [ENTER] key:
$ c

How do I disabled alias temporarily?

An alias can be disabled temporarily and the core command get called directly. Just prefix command with a backslash. Create an alias called vnstat:
$ alias vnstat='vnstat -i eth1'
$ vnstat

Sample output:

Database updated: Fri Mar 13 15:30:01 2009

	eth1

	   received:     158.48 GB (20.9%)
	transmitted:     599.82 GB (79.1%)
	      total:     758.30 GB

	                rx     |     tx     |  total
	-----------------------+------------+-----------
	yesterday      2.83 GB |   10.90 GB |   13.73 GB
	    today      1.92 GB |    7.31 GB |    9.23 GB
	-----------------------+------------+-----------
	estimated      2.97 GB |   11.28 GB |   14.25 GB

Now disabled vnstat alias temporarily, enter:
$ \vnstat
Sample output:

                     rx      /     tx      /    total    /  estimated
 eth1:
     yesterday      2.83 GB  /   10.90 GB  /   13.73 GB
         today      1.92 GB  /    7.31 GB  /    9.23 GB  /   14.24 GB

 eth0:
     yesterday    655.05 MB  /    2.02 GB  /    2.66 GB
         today    438.01 MB  /    1.43 GB  /    1.86 GB  /    2.86 GB

Another option is to type full command path:
$ /usr/bin/vnstat
You can also use any one of the following command too:
$ "vnstat"
$ 'vnstat'
$ command vnstat

But, how do I unalias permanently?

Update your shell configuration file like ~/.bashrc and remove required alias:
$ vi ~/.bashrc #or use joe text editor ##
$ unalias nameHere
$ unalias vnstat
$ source ~/.bashrc

For more info read the following help/man pages:
$ man bash
$ help source
$ help alias
$ help unalias
$ man vim

See also

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
21 comments… add one
  • techfun Mar 13, 2009 @ 20:55

    When you said:
    alias p='clear'
    I think you meant:
    alias c='clear'

  • 🐧 nixCraft Mar 13, 2009 @ 21:04

    Thanks for the heads up.

  • techfun Mar 13, 2009 @ 21:09

    No problem, I do that kind of thing all the time myself. :)

  • Tim Mar 14, 2009 @ 10:48

    You can also use `command’. If you have ls aliased to `ls -lh’, command ls will run the ls command as if there was no alias.

  • Topper Mar 14, 2009 @ 11:24

    Also, you can see all the aliases from .bashrc or .bashcompletition or something else with
    # alias TAB
    This will list all the aliases

  • Michael Wagner Mar 14, 2009 @ 15:03

    You can temporarily disable it via

    \

    or with the full pathname of the command.

    Michael

  • Michael Wagner Mar 14, 2009 @ 15:04

    Sorry, the output was not correct. You can put an \ before the alias.

  • Michael Wagner Mar 14, 2009 @ 15:06

    Sorry, the output was not correct. You can disable it when you put a \ before the alias.

    Michael

  • Topper Mar 14, 2009 @ 19:43

    Exactly – this was the meaning of author’s post! Did you read it ?

  • Michael Wagner Mar 14, 2009 @ 20:50

    Yes I read the post but I thought it was a question not a statement. Sorry for the misunderstanding.

  • Aditya Mar 15, 2009 @ 6:42

    How about unaliasing?
    say I’ve a few aliases defined in my ~/.bashrc and ls is one of them:
    alias ls=’ls -alhF’

    so on prompt to disable it temporarily I will say:

    > unalias ls

    and done……how about this solution?

  • Topper Mar 15, 2009 @ 8:45

    unalias [-a] [name …]
    Remove each name from the list of defined aliases
    I think that will be removed permanently.

    • Jeremy Feb 16, 2012 @ 14:14

      yes and no. IT does remove it permanently, however, the alias is normally generated from the .bashrc or some other file that is read in during login or opening a new terminal. So technically it is not removed permanently unless the alias commands are removed from those files as well.

    • VoidFox Jun 24, 2015 @ 12:53

      thanks just what i needed :>

  • Rory Browne Mar 16, 2009 @ 12:11

    There seem to be some useful tips here – I usually do something like /bin/rm to avoid the rm -i alias. Of course you can always use the -f argument with cancels out -i.

    Another thing you could do ( if you wanted to use an unedited version of the command ) would be to start up a sub-shell.

    Something along the lines of……

    bash
    unalias ls
    ls
    exit

    When you exit back out to the parent shell, your unalias is forgotten.

  • Kristian Apr 14, 2009 @ 16:24

    Doesn’t control-L clear the screen?

    • 🐧 nixCraft Apr 14, 2009 @ 17:54

      This is not about clearing screen. It is about disabling aliases.

  • Topper Apr 14, 2009 @ 17:46

    Yes it is ?

  • Jeremy Feb 16, 2012 @ 14:10

    Although -f cancels out the -i for rm, it does not for cp. I found this page looking for a way to temporarily disable an alias because the -f isn’t working. The script will run, but the new file is not copying over the old one. During testing, I notice its because the -f I put on the command is not actually canceling out the alias which uses the -i and its still prompting for confirmation to move the file over.

    • 🐧 nixCraft Feb 16, 2012 @ 14:31

      Use full path or \ syntax:

      # skip it
      /bin/cp -f foo bar
      # OR
      \cp -f foo bar
      
  • Harper Dec 20, 2016 @ 15:41

    Can you add in the “Why this works” part? I get why an `unalias command` would make it run in an unaliased way but why does `\` make it run unaliased? What is it about BASH that accepts the `\command` shortcut?

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.