Clear all Linux / UNIX bash shell aliases

last updated in Categories , , , , , , ,

How do I clear all Linux and UNIX bash shell aliases in single command? I have twenty bash shell aliases defined and I just need to delete them in a current session. How do I get rid of all of them?

You need to use unalias command on Linux or Unix to remove bash shell aliases. The alias command used to create aliases. It works on bash, ksh, csh and other Unix shells. This page shows how to clear or remove bash shell alises using command-line options.

How to see a list of bash shell aliases

To get a list of aliases for the current user, run:
alias
OR
alias -p

How to defined a new bash shell alias

The syntax is:
alias name='value'
The following command create a new alias named c for the commonly used clear command:
alias c='clear'
Next, to clear the screen, instead of typing clear, the user would only have to type the letter c and press the ENTER key:
c
In this example, when user type nano, open a text editor named vim:
alias nano='vim'
nano

unalias command syntax to remove aliases

The syntax is:
unalias name
unalias [option] name

To remove alias called foo, enter:
unalias foo
To clear alias named c, enter:
unalias c
Please note that alias command with no arguments or with the -p option prints the list of aliases:
$ alias
Sample outputs:

alias ll='ls -lh'
alias ls='ls --color=auto'
alias vi='vim '
alias c='clear'
alias d="/usr/local/bin/chkdomain $@"

How to clear all Linux / UNIX bash shell aliases

To remove all bash shell aliases NAMEs from the list of defined aliases pass the -a option as follows and it will remove all alias definitions:
unalias -a
Verify it:
alias
Above command removed all bash shell alias.

Sample Linux session that remove all bash shell aliases

How to remove or clear all Linux and Unix bash shell aliases
How to remove or clear all Linux and Unix bash shell aliases

Getting help of alias and unalias command

Visit this page or type the following commands:
help alias
help unalias
man alias

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Start the discussion at www.nixcraft.com

Historical Comment Archive

3 comment

    Still, have a question? Get help on our forum!