Bash Shell Temporarily Disable an Alias

by Vivek Gite · 16 comments

I've 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?

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.

Display currently defined aliases

Type the following command:
$ alias
Sample output:

alias cp='cp -i'
alias dnstop='dnstop -l 5  eth1'
alias grep='grep --color'
alias l.='ls -d .* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias mv='mv -i'
alias rm='rm -i'
alias update='yum update'
alias updatey='yum -y update'
alias vi='vim'
alias vnstat='vnstat -i eth1'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
alias vnstat='vnstat -i eth1'

Creating 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

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 16 comments… read them below or add one }

1 techfun 03.13.09 at 8:55 pm

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

2 Vivek Gite 03.13.09 at 9:04 pm

Thanks for the heads up.

3 techfun 03.13.09 at 9:09 pm

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

4 Tim 03.14.09 at 10:48 am

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.

5 Topper 03.14.09 at 11:24 am

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

6 Michael Wagner 03.14.09 at 3:03 pm

You can temporarily disable it via

\

or with the full pathname of the command.

Michael

7 Michael Wagner 03.14.09 at 3:04 pm

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

8 Michael Wagner 03.14.09 at 3:06 pm

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

Michael

9 Topper 03.14.09 at 7:43 pm

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

10 Michael Wagner 03.14.09 at 8:50 pm

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

11 Aditya 03.15.09 at 6:42 am

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?

12 Topper 03.15.09 at 8:45 am

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

13 Rory Browne 03.16.09 at 12:11 pm

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.

14 Kristian 04.14.09 at 4:24 pm

Doesn’t control-L clear the screen?

15 Topper 04.14.09 at 5:46 pm

Yes it is ?

16 Vivek Gite 04.14.09 at 5:54 pm

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

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All