Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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 main becomes gpm.
  • They fix your personal defaults. cp -i (ask before overwriting) as plain cp protects you from your own mistakes.
  • They are the first customization almost every Linux user makes — which is also why everyone else’s .bashrc is full of them.

An alias is just a substitution. Learn alias, unalias, and type, 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

MistakeFix
Alias vanishes in a new terminalAdd it to ~/.bashrc (or ~/.zshrc), not just the prompt
Alias not working in a scriptScripts don’t load aliases — use a shell function
alias ll=ls -l errorsQuote the value: alias ll='ls -l'
Forgetting what an alias doestype ll or alias ll to see its definition
Aliases clashing with commandstype -a ll shows every command/alias of that name
PageWhat It Covers
Environment VariablesWhere aliases live and how startup files work
$PATHWhy shell customization exists at all
HistoryRecalling commands by number instead of alias
Shell ScriptingFunctions — the scriptable alternative to aliases
bash / sh / zshWhich startup file your shell actually reads

Aliases Cheatsheet

TaskCommand
List all aliasesalias
Define an aliasalias ll='ls -l'
See one aliasalias ll
Make it permanentappend to ~/.bashrc / ~/.zshrc
Reload the startup filesource ~/.bashrc
Remove an aliasunalias ll
Remove all aliasesunalias -a
Check what a name really istype -a ll