LinuxCommandLibrary

unalias

Remove a shell alias definition

TLDR

Remove an alias

$ unalias [alias_name]
copy

Remove all aliases
$ unalias -a
copy

SYNOPSIS

unalias [-a] name [name ...]

PARAMETERS

-a
    Removes all alias definitions in the current shell session.

name
    The specific name of the alias to be removed. Multiple alias names can be specified, separated by spaces.

DESCRIPTION

The unalias command is used to remove or undefine aliases previously set in the current shell session. Aliases provide a way to substitute a long command or a sequence of commands with a shorter, custom name. When an alias is no longer needed, or if it was defined incorrectly, unalias allows you to quickly remove its definition.

Once an alias is undefined, the shell will no longer perform the substitution, and if you type the alias name, it will either execute a command with that literal name (if one exists in your PATH) or report an error if no such command or function is found. It's important to note that unalias only affects the current shell session; aliases defined in persistent shell configuration files (like ~/.bashrc or ~/.zshrc) will reappear in new shell sessions unless those files are modified directly.

CAVEATS

The unalias command primarily affects the current shell session. This means that if an alias was defined in a startup file (e.g., .bashrc), it will reappear when a new shell session is started, unless you also edit the startup file to remove its definition.

Furthermore, unalias typically does not support shell globbing or wildcards for alias names (e.g., unalias l* will not remove all aliases starting with 'l' in Bash); you must specify each alias name explicitly or use the -a option to remove all.

SHELL BUILTIN

In most popular shells, such as Bash, Zsh, and Ksh, unalias is a shell builtin command rather than an external executable. This means it is an integral part of the shell itself, allowing it to directly manipulate the shell's internal alias table without needing to fork a new process. This makes its operation very fast and efficient.

HISTORY

The concept of aliasing commands has been a fundamental feature of various Unix shells for a long time, providing user convenience and customization. The unalias command emerged naturally alongside the alias command to provide a symmetric way of managing these definitions. It has been a standard builtin command in modern shells like Bash, Zsh, and Ksh since their early development, reflecting its utility in interactive shell usage.

SEE ALSO

alias(1), bash(1), zsh(1), ksh(1)

Copied to clipboard