Aliases Command Guide for Bash, Sh & Zsh
Shortcuts for long commands.
What Are Aliases, and Why Use Them?
An alias is a nickname for a command. Type ll and you get whatever ls -l --color=auto would have given you; type gs and you get git status. Aliases live in your shell — usually defined in ~/.bashrc or ~/.zshrc — and they save you thousands of keystrokes over the life of a terminal session.
Why Learn Aliases?
- They eliminate typing fatigue.
git pull origin main && git push origin mainbecomesgpm. - They fix your personal defaults.
cp -i(ask before overwriting) as plaincpprotects you from your own mistakes. - They are the first customization almost every Linux user makes — which is also why everyone else’s
.bashrcis full of them.
An alias is just a substitution. Learn
alias,unalias, andtype, and you understand every customization in every dotfile you will ever read.
1. The alias Command
alias # list every defined alias
alias ll='ls -l' # define a new alias
alias ll # show one alias's definition
2. Making Aliases Permanent
Aliases typed at the prompt die when the terminal closes. Put them in your shell’s startup file (see environment-variables):
echo "alias gs='git status'" >> ~/.bashrc
source ~/.bashrc # reload without opening a new terminal
# For zsh users the file is ~/.zshrc instead.
# Common safe defaults worth aliasing:
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
3. Removing Aliases
unalias ll # remove it for the current session
unalias -a # remove all aliases
4. Aliases in Scripts
#!/bin/bash
# Aliases are NOT available in non-interactive scripts.
# Use functions instead:
ll() {
ls -l "$@"
}
Common Pitfalls
| Mistake | Fix |
|---|---|
| Alias vanishes in a new terminal | Add it to ~/.bashrc (or ~/.zshrc), not just the prompt |
| Alias not working in a script | Scripts don’t load aliases — use a shell function |
alias ll=ls -l errors | Quote the value: alias ll='ls -l' |
| Forgetting what an alias does | type ll or alias ll to see its definition |
| Aliases clashing with commands | type -a ll shows every command/alias of that name |
Related Pages
| Page | What It Covers |
|---|---|
| Environment Variables | Where aliases live and how startup files work |
$PATH | Why shell customization exists at all |
| History | Recalling commands by number instead of alias |
| Shell Scripting | Functions — the scriptable alternative to aliases |
| bash / sh / zsh | Which startup file your shell actually reads |
Aliases Cheatsheet
| Task | Command |
|---|---|
| List all aliases | alias |
| Define an alias | alias ll='ls -l' |
| See one alias | alias ll |
| Make it permanent | append to ~/.bashrc / ~/.zshrc |
| Reload the startup file | source ~/.bashrc |
| Remove an alias | unalias ll |
| Remove all aliases | unalias -a |
| Check what a name really is | type -a ll |