Quick viewing(Text Mode)

Bash Shell Temporarily Disable an Alias

Bash Shell Temporarily Disable an Alias

≡ Menu

Tutorials Troubleshooting Nginx Networking MySQL Google Cloud Platform Amazon Cloud Rackspace Cloud Computing Linux CentOS Debian / Ubuntu Ubuntu Linux Suse RedHat and Friends Slackware Linux AIX Mac OS X FreeBSD FreeBSD Jails (VPS) Openbsd Solaris See all tutorial topics Contact us Linux Scripting Guide RSS/FEED nixCraft Linux and Unix tutorials for new and seasoned sysadmin. Bash Shell Temporarily Disable an by Vivek Gite on March 13, 2009 in BASH Shell, CentOS, Debian / Ubuntu, FreeBSD, Linux, RedHat and Friends, Suse, Troubleshooting, Ubuntu Linux, UNIX

I've couple of shell aliases defined in ~/.bashrc . 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.It is Tutorial details also useful for creating your own commands on a Linux, OS X, FreeBSD, Difficulty Easy (rss) OpenBSD, Ubuntu/Debian/Red hat/CentOS/Fedora and Unix-like operating Root privileges No systems. Requirements None Estimated completion 2m Display currently defined aliases

Type the following command: $ alias Sample outputs: alias ='cp -i' alias dnstop='dnstop -l 5 eth1' alias ='grep --color' alias l.=' -d .* --color=tty' alias ll='ls -l --color=tty' alias ls='ls --color=tty' alias ='mv -i' alias ='rm -i' alias update='yum update' alias updatey='yum -y update' alias ='vim' alias vnstat='vnstat -i eth1' alias ='alias | /usr/bin/which --tty-only --read-alias --show- --show-tilde' alias vnstat='vnstat -i eth1' Creating an alias

Create an alias called c for the commonly used command, which clear the screen: $ alias c='clear' Then, to clear the screen, instead of typing clear, the user would only have to 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 : $ /usr/bin/vnstat

But, how do I unalias permanently?

Update your shell like ~/.bashrc and remove required alias: $ vi ~/.bashrc $ unalias nameHere $ unalias vnstat $ source ~/.bashrc

Bash Shell: Ignore Clear all Linux / Aliases and Ubuntu Set User out if shell How do I use shell UNIX bash shell Functions When Profile Under Bash command is aliased aliases under Linux? aliases Running A… Shell or not

Pass Command Line Arguments To a Bash Alias Command

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 20 comments… add one }

techfun March 13, 2009, 8:55 pm

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

Reply nixCraft March 13, 2009, 9:04 pm

Thanks for the heads up.

Reply Link techfun March 13, 2009, 9:09 pm

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

Reply Link Tim March 14, 2009, 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.

Reply Link Topper March 14, 2009, 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

Reply Link Michael Wagner March 14, 2009, 3:03 pm

You can temporarily disable it via

\

or with the full pathname of the command.

Michael

Reply Link Michael Wagner March 14, 2009, 3:04 pm

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

Reply Link Michael Wagner March 14, 2009, 3:06 pm

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

Michael

Reply Link Topper March 14, 2009, 7:43 pm

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

Reply Link Michael Wagner March 14, 2009, 8:50 pm

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

Reply Link Aditya March 15, 2009, 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?

Reply Link Topper March 15, 2009, 8:45 am

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

Reply Link Jeremy February 16, 2012, 2:14 pm

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.

Reply Link VoidFox June 24, 2015, 12:53 pm

thanks just what i needed :>

Reply Link Rory Browne March 16, 2009, 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

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

Reply Link Kristian April 14, 2009, 4:24 pm

Doesn’t control-L clear the screen?

Reply Link nixCraft April 14, 2009, 5:54 pm

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

Reply Link Topper April 14, 2009, 5:46 pm

Yes it is ?

Reply Link Jeremy February 16, 2012, 2:10 pm

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 the file over.

Reply Link nixCraft February 16, 2012, 2:31 pm

Use full path or \ syntax:

# skip it /bin/cp -f foo bar # OR \cp -f foo bar Reply Link

Leave a Comment

Name *

Email *

Comment

Submit

Next FAQ: Linux Uninstall VMWare Server Software

Previous FAQ: Postfix Configure Multiple ISP Client SMTP Authentication

To search, type and hit enter Featured Articles:

30 Cool Open Source Software I Discovered in 2013 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X 30 Nmap Command Examples For Sys/Network Admins 25 PHP Security Best Practices For Sys Admins 20 Linux System Monitoring Tools Every SysAdmin Should Know 20 Linux Server Hardening Security Tips Linux: 20 Iptables Examples For New SysAdmins Top 20 OpenSSH Server Best Security Practices Top 20 Nginx WebServer Best Security Practices 20 Examples: Sure Unix / Linux Configuration Files Are Free From Syntax Errors 15 Greatest Open Source Terminal Applications Of 2012 My 10 UNIX Command Line Mistakes Top 10 Open Source Web-Based Project Management Software Top 5 Email Client For Linux, Mac OS X, and Windows Users The Novice Guide To Buying A Linux Laptop

Follow +1

+ 179,856

Follow @nixcraft

©2000-2015 nixCraft. All rights reserved. Privacy Policy - Terms of Service - Questions or Comments The content is copyrighted to nixCraft and may not be reproduced on other websites.