How To List/Clear All Bash Shell Aliases in Linux

This post will guide you how to list or clear all bash shell aliases in your Linux or Unix Operating systems. How do I clear all bash shell aliases using unalias command in your Linux system.

How To Clear All Bash Shell Aliases in Linux1

Alias Command


Alias command can be used to define or display aliases in your current shell prompt under Linux system. Without arguments, `alias‘ prints the list of aliases in the reusable form `alias NAME=VALUE’ on standard output. Otherwise, an alias is defined for each NAME whose VALUE is given. A trailing space in VALUE causes the next word to be checked foralias substitution when the alias is expanded.

Options:

-p print all defined aliases in a reusable format

Unalias Command


Unalias command can be used to remove each NAME from the list of defined aliases.

Options:

-a remove all alias definitions

List All Aliases


If you want to list all aliases for the current bash shell in your Linux system, and you can run the following command:

$ alias

or

$ alias -p

Outputs:

[root@mydevops ~]# alias -p
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='(alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot'
alias xzegrep='xzegrep --color=auto'
alias xzfgrep='xzfgrep --color=auto'
alias xzgrep='xzgrep --color=auto'
alias zegrep='zegrep --color=auto'
alias zfgrep='zfgrep --color=auto'
alias zgrep='zgrep --color=auto'

Create a new Alias


If you want to defind a new alias for a given command, and you can use alias command, type:

$ alias name="command"

For example, you wish to create a new alias named “dfh” for command “df -h“, and you can use the following command:

$ alias dfh="df -h"

Outputs:

[root@mydevops ~]# alias dfh="df -h"
[root@mydevops ~]#
[root@mydevops ~]#
[root@mydevops ~]# dfh
Filesystem Size Used Avail Use% Mounted on
devtmpfs 648M 0 648M 0% /dev
tmpfs 663M 0 663M 0% /dev/shm
tmpfs 663M 9.5M 654M 2% /run
tmpfs 663M 0 663M 0% /sys/fs/cgroup
/dev/mapper/cl_mydevops-root 41G 4.5G 36G 12% /
/dev/mapper/cl_mydevops-home 20G 299M 20G 2% /home
/dev/sda1 976M 133M 777M 15% /boot
tmpfs 133M 28K 133M 1% /run/user/42
tmpfs 133M 3.5M 130M 3% /run/user/0
/dev/sr0 4.3G 4.3G 0 100% /run/media/root/CentOS 7 x86_64

Clear All Aliases


If you want to unalias a alias in your bash shell, and you can use unalias command. For example, you want to remove alias called “dfh“, just type:

$ unalias dfh

And If you wan to unalias or clear all aliases in your current bash shell, and you can pass the “-a” option to the unalias command, type:

$ unalias -a

Then you can verify it with the following command:

$ alias

Conclusion


You should know that how to define/list/clear all aliases using alias/unalias commands in your CentOS or RHEL or Ubuntu system.

You might also like:

Sidebar



back to top