Working with Bash Aliases (Alias/Unalias)

  • HOME
  • >
  • BASH
  • >
  • Working with Bash Aliases (Alias/Unalias)
Last Updated: 
Tags:  bash alias

Bash Aliases allow a string to be substituted for a word when it is used as the first word of a simple command. The shell maintains a list of aliases that may be set and unset with the alias and unalias builtin commands.

You can set your aliases into your .bashrc file. Below is some common aliases:

# .bashrc example
alias ls="ls -color=auto"
alias dir="ls -color=auto -format=vertical"  
alias vdir="ls -color=auto -format=long"
alias ll="ls -l"
alias la="ls -A"
alias l="ls -CF"

The reverse action exist in order to unset an alias, you will simply use the unalias builtin command.

# unset "ll" alias  
[root@host ~]$ unalias ll

# unset all aliases  
[root@host ~]$ unalias -a

Aliases are not expanded when your shell isn't interactive, unless the expand_aliases shell option is set using shopt.

[root@host ~]$ shopt -s expand_aliases

👉 Read more about aliases with the post to Find How a Bash Command will be Interpreted

Related bash posts that you may like
What is the Bash Null Command?
Learn about the Bash null command, also known as the POSIX shell colon command. This post cover concrete use cases and pitfalls to avoid.
How To Format Date and Time in Linux, macOS, and Bash?
Find out how to manipulate date and time on linux and macOS systems as well as natively in the Bash shell. This post covers all you need to know to format a date from your shell.
How To Use Option as Meta Key in macOS Terminal?
The Meta Key is a modifier key that can be quite helpful to improve your productivity while working in a terminal and bash. This post cover how to enable from the command line the Meta Key in macOS Terminal.