To create an alias, use alias ALIAS_NAME="ALIAS_VALUE"
:
alias ll="ls -al"
To remove the alias, use the unalias
command:
unalias ll
To see a list of all your aliases, use the alias
command:
alias
To make aliases permanent, we have to set them in a file that’s read when you open Terminal. Some common ones are ~/.bashrc
and ~/.bash_profile
.
For this example, let’s use ~/.bash_profile
.
From the command line, open to edit the file by running the following:
nano ~/.bash_profile
Add the following lines either at the bottom of the file or wherever you’d like:
# -------
# Aliases
# -------
alias ll="ls -al"
To reload the Terminal with set profile ~/.bash_profile
. Use the source command:
source ~/.bash_profile
# -------
# Aliases
# -------
alias clr="clear" # Clear your terminal screen
alias flush="sudo discoveryutil udnsflushcaches" # Flush DNS (Yosemite)
alias flush="killall -HUP mDNSResponder" # Flush DNS (Mavericks, Mountain Lion, Lion)
alias flush="dscacheutil -flushcache" # Flush DNS (Snow Leopard, Leopard)
alias ip="curl icanhazip.com" # Your public IP address
alias ll="ls -al" # List all files in current directory in long list format
alias ldir="ls -al | grep ^d" # List all directories in current directory in long list format
alias o="open ." # Open the current directory in Finder
alias ut="uptime" # Computer uptime
alias opencode="open -a \"Visual Studio Code\""
Reference: Link
Open .zshrc
file in vim:
vi ~/.zshrc
Add the following lines:
source ~/.bash_profile
Reload zsh
:
source ~/.zshrc