In Linux, the unalias command is used to remove aliases previously defined by the user. Aliases are custom shorthand commands that allow you to create shorter or more convenient names for frequently used commands. The unalias command helps you to delete these custom aliases, restoring the original behavior of the commands.
The basic syntax of the unalias command is:
Bash
unalias [alias_name]Here is a table outlining the parameters of the unalias command:
| Parameter | Description |
|---|---|
[alias_name] | Optional. Specifies the name of the alias you want to remove. If not provided, the unalias command will display a list of currently defined aliases and prompt you to choose one to remove. |
| Parameter | Description |
|---|---|
| -a | Removes all aliases. |
| -r | Removes the specified alias. |
Examples:
- Remove the alias for
ll(previously defined asls -lh --color=auto):
Bash
unalias ll- Delete an alias called
cls(previously defined asclear):
Bash
unalias cls- Remove an alias named
desktop(previously defined ascd ~/Desktop):
Bash
unalias desktop- Delete an alias called
psa(previously defined asps -aux):
Bash
unalias psa- Display a list of currently defined aliases and prompt to remove one:
Bash
unaliasSample output:
Bash
alias ll='ls -lh --color=auto'
alias cls='clear'
alias desktop='cd ~/Desktop'
...Choose an alias to remove (e.g., enter ll to remove the ll alias).
- Attempt to remove a non-existing alias (no error occurs if the alias does not exist):
Bash
unalias non_existing_alias
# Create an alias for the ls command called lsdir
alias lsdir='ls -al'
# Use the lsdir alias
lsdir
# Remove the lsdir alias
unalias lsdir
# Try to use the lsdir alias again
lsdirThe second time you run the lsdir command, you will get an error message because the alias has been removed.
The unalias command is useful for managing aliases and cleaning up your shell environment by removing aliases you no longer need or want to revert to the default behavior of specific commands.