Python Command Aliases: alias, unalias & Persistence
The `alias` command creates custom shorthand abbreviations for long or frequently used commands. Aliases can also enforce safety flags (e.g. `alias rm="rm -i"`). To persist aliases across terminal sessions, they are defined in `~/.bashrc` or `~/.bash_aliases`.
"An alias is like programming a speed-dial button on your phone: instead of dialing an 11-digit number every time, you press button "1"."
Deep Dive: How It Works
Syntax: `alias name="command --flags"` (Note: no spaces around the equals sign `=`).
Listing and Removing: Run `alias` with no args to view active aliases; run `unalias <name>` to remove an alias.
Bypassing Aliases: Prefix a backslash `\rm file.txt` or use `command rm file.txt` to execute the raw underlying binary ignoring any defined alias.
Syntax Blueprint
alias ll="ls -lah" alias gs="git status" unalias ll \command_name # Bypass alias
Define aliases with no spaces around =, remove with unalias, and bypass with leading backslash.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Expecting aliases defined in ~/.bashrc to work inside automated bash scripts.Why it happens: Bash disables alias expansion in non-interactive subshells for deterministic execution.
How to fix: Use shell functions instead of aliases inside scripts for reusable helpers.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Create and Execute a Custom Alias
Enable alias expansion with `shopt -s expand_aliases`.
Create an alias `zen` that runs `echo "ZenCompiler Active"`.
Execute `zen`.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.