↑↓ move Enter open Esc close

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

OptionWhat it does
aliasList all current aliases.
alias x='…'Define (this session; persist in ~/.bashrc).
unalias xRemove one.
\cmdBypass an alias once (run the real command).
type xReveal 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

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

Want to build real fluency? The interactive course takes you through alias and every other essential command with guided, checked exercises.