The alias command in Linux
alias defines a shorthand the shell expands before running: alias ll='ls -lah' makes ll a real command in your fingers. Aliases personalize the shell — shortcuts for long incantations, safety nets like rm -i, corrected typos. They live in ~/.bashrc; for anything needing arguments in the middle, graduate to a shell function.
How alias works
Aliases are textual substitution performed by the shell's parser: when the first word of a command matches an alias, it is replaced before parsing continues. That early, first-word-only expansion defines their limits — no arguments in the middle, no use mid-command — and their charm: zero overhead, pure convenience.
They are also interactive-only by default: non-interactive shells (the kind that run scripts) skip alias expansion deliberately, so scripts mean exactly what they write. The moment a shortcut needs argument placement or logic, the right tool is a shell function — real parameters, real body — which is why seasoned dotfiles hold a few aliases and many small functions.
Syntax
alias NAME='COMMAND' | unalias NAME Common options
| Option | What it does |
|---|---|
alias | List all current aliases. |
alias x='…' | Define (this session; persist in ~/.bashrc). |
unalias x | Remove one. |
\cmd | Bypass an alias once (run the real command). |
type x | Reveal what x actually is: alias, function or binary. |
How to use alias: examples
$ alias ll='ls -lah' The universal first alias.
$ alias gs='git status' gl='git log --oneline -15' Git verbs shrink to two letters — several aliases in one line.
$ alias update='sudo apt update && sudo apt upgrade' A routine becomes a word.
$ type ll Debugging a surprise: see whether a name is an alias and what it expands to.
Real-world use cases for alias
The personal safety layer
alias rm='rm -i' cp='cp -i' mv='mv -i' on machines where you are tired adds a confirmation between you and destruction. Bypass consciously with \rm when scripting fingers are on.
Compressing your top ten
History audit: history | awk '{print $2}' | sort | uniq -c | sort -nr | head names your most-typed commands — alias the top five. Ten minutes of dotfile work, years of keystrokes back.
Pro tips and common mistakes
- Aliases live in ~/.bashrc; defining one at the prompt is a session-only experiment.
- Arguments in the middle need a function, not an alias: mkcd() { mkdir -p "$1" && cd "$1"; }.
- type name unmasks any command that behaves unexpectedly — the alias detector.
Frequently asked questions about alias
My alias disappears in new terminals — why?
alias defines it in the current shell only. Add the line to ~/.bashrc and it loads with every interactive shell.
Alias with arguments in the middle?
Aliases only append arguments at the end. Use a function in .bashrc: mkcd() { mkdir -p "$1" && cd "$1"; }.
Do aliases work in scripts?
No — scripts run non-interactive shells that skip them (by design: scripts should be explicit). Spell commands out in scripts.
Related commands
Print text and variables, and write or append to files with > and >>.
historyList, search and re-run previous commands — plus Ctrl+R, !! and the tricks that save hours.
env & exportHow configuration flows into processes — PATH, export, and why edits "don't stick".