Shell
shellshell-scriptingGuideBeginner
Shell Aliases & Custom Shortcuts
Create terminal command shortcuts and aliases in Bash and Zsh, manage persistent alias files, and handle positional arguments.
Verified: 2026-09-30
Tested on:bash 5.x
Platforms:
linuxmacos
#shell#bash#zsh#aliases#productivity
What is a Shell Alias?
An Alias is a custom keyboard shortcut or abbreviation for a longer shell command.
1. Creating Temporary and Persistent Aliases
# Temporary (active for current terminal session only)
alias gs="git status"
alias ll="ls -la"To make aliases permanent, add them to your ~/.bashrc (or ~/.zshrc on macOS):
# Append to shell config
cat << 'EOF' >> ~/.bashrc
# Custom Developer Aliases
alias ll="ls -lah"
alias gs="git status -sb"
alias ga="git add"
alias gc="git commit -m"
alias gp="git push"
alias dco="docker compose"
alias pdev="pnpm dev"
alias ports="sudo ss -tulpn"
EOF
# Reload configuration
source ~/.bashrc2. Listing and Removing Aliases
# List all active aliases
alias
# Remove specific alias
unalias gs3. Aliases vs Functions for Arguments
Aliases cannot take positional arguments (e.g. $1, $2). If you need dynamic arguments, use a Shell Function instead:
# ❌ Aliases cannot interpolate arguments in the middle:
# alias mcd="mkdir -p $1 && cd $1" (Does not work as expected)
# ✅ Use a shell function instead:
mcd() {
mkdir -p "$1" && cd "$1"
}Shell Variables & Parameter Expansion
Define shell variables, understand double vs single quoting rules, command substitution $(), and default parameter expansion in Bash.
Bash Scripting Fundamentals & set -euo pipefail
Write robust, production-ready Bash scripts with shebang lines, argument parsing, error trapping, and strict mode.