alias / unalias
Overview
alias is a shell builtin that creates command shortcuts in the current shell session. Aliases are primarily for interactive convenience. They are not automatically available in non-interactive scripts (unless you explicitly enable/source them). For anything with arguments or logic, prefer a shell function.
Persist aliases in ~/.bashrc, ~/.zshrc, or a dedicated ~/.bash_aliases sourced from your rc file.
Syntax
alias
alias name='command string'
alias name=$'command with specials'
unalias name
unalias -aExamples with Explanations
Everyday shortcuts
alias ll='ls -lah'
alias la='ls -A'
alias gs='git status'
alias ..='cd ..'
alias ...='cd ../..'
alias grep='grep --color=auto'
alias ip='ip -c'
alias please='sudo'List and inspect
alias
alias ll
type ll
type -a lsPersist (bash)
# ~/.bashrc
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi# ~/.bash_aliases
alias ll='ls -lah'
alias dc='docker compose'Then source ~/.bashrc or open a new shell.
Remove
unalias ll
unalias -a # nuclear; current shell onlyBypass aliases
command ls
\ls
/bin/lsEssential when an alias breaks a scripted expectation interactively.
sudo and alias expansion (bash)
alias sudo='sudo '
# trailing space makes bash expand the next word as an alias
sudo ll # may work if ll is aliasBetter as functions
mkcd() { mkdir -p -- "$1" && cd -- "$1"; }
backup() { cp -a -- "$1" "$1.bak.$(date +%Y%m%d%H%M%S)"; }Aliases do not take parameters cleanly; functions do.
Safety alias caveats
alias rm='rm -i'
# feels safe; non-interactive scripts still use raw rm
# other users/shells unaffectedNotes / Pitfalls
- Non-interactive bash does not expand aliases by default (
shopt expand_aliasescan enable, but functions are clearer). - Quote carefully:
alias e=echo hiis wrong; usealias e='echo hi'. - Recursive aliasing and shadowing builtins can confuse (
alias cd=...— avoid unless intentional). - zsh/fish have richer abbreviation systems; syntax differs.
- Exporting aliases to child shells is not a thing — source rc files instead.
2026-relevant notes
- Dotfile managers (chezmoi, yadm) commonly template alias collections per machine.
- Prefer shared functions in a small
~/.config/shell/functionsfor portability across bash/zsh when possible. - Tool-provided completions > heavy aliases for complex CLIs (
kubectl,docker).
Additional Resources
help alias,help unalias,man bash