Linux unalias Command: Remove Command Aliases

unalias is a built-in command that removes aliases registered in the current Bash shell. You can delete a specific alias or remove all aliases with the -a option, but it does not automatically erase the definitions saved in the startup files.

It is useful when unexpected options are applied due to aliases or when it is difficult to execute the original command. Understanding the difference between temporary removal and permanent removal is key.

What is the unalias command?

If alias registers a command name and a replacement string, unalias deletes that registration in the current Bash session. After deletion, if you enter the same name, Bash will look again for the next candidates such as functions, built-in commands, or executables in PATH.

This article is based on Bash. Other shells may have commands with the same name, but supported options and configuration files may differ.

Basic Syntax

unalias [-a] [name...]

Specifying one or more names will remove the corresponding aliases. -a removes all aliases in the current shell.

Removing a specific alias

alias ll='ls -alF'
unalias ll

You can check the state before and after deletion as shown below.

alias ll
unalias ll
type ll

After removing an alias, if there is a function or executable file with the same name, that target can be selected. Do not simply assume that "the command has disappeared"; it is recommended to check the remaining candidates with type -a name.

Removing multiple aliases at once

unalias ll la grep

If there is an undefined alias among the specified names, unalias may return a failure status. Keep this in mind when using the result in automation scripts.

Removing all aliases

unalias -a

-a deletes all the aliases in the current shell. Because it can remove not only personal settings but also aliases provided by the distribution for convenience or safety, use it carefully unless it is a temporary shell aimed at narrowing down the cause of a problem.

To save the current list before deleting, you can output it like this.

alias -p

Difference between temporary removal and permanent removal

Removed only in the current terminal

`unalias` only changes the alias table of the current Bash process. When you close the terminal and start a new shell, aliases in startup files like `~/.bashrc` will be redefined.

Remove in a new terminal as well

To permanently remove an alias, you need to find the configuration file where the alias is defined and delete the corresponding line or comment it out.

grep -n "alias ll=" ~/.bashrc ~/.bash_aliases 2>/dev/null

After modifying the settings, open a new shell or apply them to the current shell with the following command.

source ~/.bashrc

It may also be defined in system-wide settings like `/etc/bash.bashrc` or `/etc/profile.d/`. Before changing system files, consider redefining it in user settings or removing it only in the necessary session first.

Bypass an alias just once without deleting it

If you only want to run the original command once, there is no need to delete the alias. You can either put a backslash in front of the command name or use the absolute path of the executable.

\ls
/usr/bin/ls

A backslash prevents that word from being expanded as an alias. Using the absolute path runs the specified file while avoiding functions with the same name, like PATH searches.

Aliases, functions, and variables have different removal methods

Target Removal Command How to check
Alias unalias name alias name or type name
Shell functions unset -f name declare -F name or type name
Shell Variable unset name declare -p name
Executable file Use file management commands type -a name or command -v name

unalias does not remove functions or files with the same name. If you misidentify the type of the command, the intended target may remain, so check first with type.

Use safely in scripts

To remove only if defined, check the exit status of alias first.

if alias ll >/dev/null 2>&1; then
  unalias ll
fi

However, non-interactive Bash does not perform alias expansion by default, so there are not many situations where a regular script needs to remove user aliases. It is better to write scripts so that they do not rely on the personal settings of an interactive shell.

Common issues

after unalias, the alias reappears in a new terminal.

This is because it is being redefined in ~/.bashrc, ~/.bash_aliases, or system startup files. You need to find the definition location and modify it.

unalias: not found error occurs.

The specified name is likely not an alias in the current shell. Use type -a name to check whether it is a function, built-in command, or executable file.

The command behavior still seems different.

There may be a shell function with the same name or multiple executable files in different paths. Use type -a name to check all candidates, and if necessary, clear Bash's command path cache with hash -r before checking again.

Selection according to usage situation

Situation Recommended Method
Execute the original command only once Use name or the absolute path.
Remove alias in the current terminal Use unalias name.
Temporarily remove the effects of all aliases Check the list and then use unalias -a.
Remove in a new terminal as well Modify the startup file where the alias is defined.
Remove a function with the same name Use unset -f name.

Frequently Asked Questions

Can I recover if I run unalias -a?

There is no function to directly revert the alias definitions of the current shell. Aliases stored in the startup file can be reloaded with source ~/.bashrc, but aliases made only from the command line need to be redefined.

Does unalias affect other terminals as well?

No. Each terminal's shell process has its own separate alias table, so the unalias run in the current shell does not directly affect other shells.

What runs if you enter the same name as the deleted alias?

Bash searches for remaining functions, built-in commands, and executable files in PATH according to the command search rules. The actual selection result can be checked with type name.

Related articles and official documentation

More in This Category
Linux sort Command: Sort Text Lines

Linux sort Command: Sort Text Lines

Learn how to sort text lines with the Linux sort command, including practical examples, key options, and important precautions.

Linux wc Command: Count Lines, Words, Characters, and Bytes

Linux wc Command: Count Lines, Words, Characters, and Bytes

Learn how to use the Linux wc command to count lines, words, characters, and bytes in files or standard input, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux host Command: Look Up DNS Names and Addresses

Linux host Command: Look Up DNS Names and Addresses

Learn how to look Up DNS Names and Addresses with the Linux host command, including practical examples, key options, and important precautions.

Best Linux Distributions for Web Servers: Ubuntu, Debian, or Rocky Linux?

Best Linux Distributions for Web Servers: Ubuntu, Debian, or Rocky Linux?

Compare Ubuntu Server, Debian, and Rocky Linux for web hosting based on support lifecycle, package freshness, documentation, operational stability, and application requirements.

Linux realpath Command: Resolve Absolute and Canonical Paths

Linux realpath Command: Resolve Absolute and Canonical Paths

Learn how to use the Linux realpath command to resolve relative paths, symbolic links, and redundant path components, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux sudo Command: Run Commands with Elevated or Another User's Privileges

Linux sudo Command: Run Commands with Elevated or Another User's Privileges

Learn how to use the Linux sudo command to run approved commands with elevated privileges or as another user, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux nslookup Command: Query DNS Names and Records

Linux nslookup Command: Query DNS Names and Records

Learn how to query DNS Names and Records with the Linux nslookup command, including practical examples, key options, and important precautions.

Linux type Command: Identify How a Command Is Resolved

Linux type Command: Identify How a Command Is Resolved

Learn how to use the Linux type command to identify aliases, functions, built-ins, keywords, and executable paths, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux dd Command: Copy and Convert Data by Blocks

Linux dd Command: Copy and Convert Data by Blocks

Learn how to copy and convert files or block devices with Linux dd, choose block sizes and ranges, display progress, verify results, and avoid overwriting the wrong device.

Linux chown Command: Change File Owner and Group

Linux chown Command: Change File Owner and Group

Learn how to change File Owner and Group with the Linux chown command, including practical examples, key options, and important precautions.