The Compound Effect of Aliases
Saving 3 seconds per command, 50 times a day, is 2.5 minutes saved per day. Over a year: 15 hours. But the real value is cognitive — you stop thinking about command syntax and think about what you want to accomplish.
Add these to ~/.bashrc (bash) or ~/.zshrc (zsh):
Navigation
# Go up directories
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
# Quick access
alias home='cd ~'
alias desk='cd ~/Desktop'
alias proj='cd ~/Projects'
# List with details
alias ll='ls -la'
alias la='ls -A'
alias l='ls -CF'
# If you have eza installed (recommended)
alias ls='eza --icons'
alias ll='eza -la --icons --git'
alias tree='eza --tree --level=3'
Git
alias g='git'
alias gs='git status -sb'
alias ga='git add'
alias gaa='git add -A'
alias gc='git commit -m'
alias gca='git commit --amend --no-edit'
alias gp='git push'
alias gpl='git pull --rebase'
alias gl='git log --oneline --graph --decorate --all'
alias gd='git diff'
alias gds='git diff --staged'
alias gco='git checkout'
alias gcb='git checkout -b'
alias gb='git branch -v --sort=-committerdate'
alias grb='git rebase'
alias gst='git stash push -m'
alias gstp='git stash pop'
npm / Node
alias ni='npm install'
alias nid='npm install -D'
alias nr='npm run'
alias nrd='npm run dev'
alias nrb='npm run build'
alias nrt='npm test'
alias nrl='npm run lint'
alias nlg='npm list -g --depth=0'
Docker
alias d='docker'
alias dc='docker compose'
alias dcu='docker compose up -d'
alias dcd='docker compose down'
alias dcl='docker compose logs -f'
alias dcr='docker compose restart'
alias dps='docker ps'
alias dpsa='docker ps -a'
alias di='docker images'
alias drm='docker rm $(docker ps -aq)' # Remove all stopped containers
alias drmi='docker rmi $(docker images -q)' # Remove all images
Utilities
# Better defaults
alias cp='cp -iv' # Interactive + verbose
alias mv='mv -iv' # Interactive + verbose
alias rm='rm -i' # Interactive (confirms before deleting)
alias mkdir='mkdir -pv' # Create parents, verbose
# Quick file viewing
alias cat='bat' # Syntax-highlighted cat (install bat first)
alias grep='rg' # Faster grep (install ripgrep first)
# System
alias ports='lsof -i -P -n | grep LISTEN' # See what's using which port
alias myip='curl -s ifconfig.me' # Public IP
alias localip="ipconfig getifaddr en0" # Local IP (macOS)
alias flush='sudo dscacheutil -flushcache' # Flush DNS (macOS)
# Quick edit config files
alias zshrc='${EDITOR:-vim} ~/.zshrc && source ~/.zshrc'
alias bashrc='${EDITOR:-vim} ~/.bashrc && source ~/.bashrc'
alias gitconfig='${EDITOR:-vim} ~/.gitconfig'
Functions (for More Complex Tasks)
These need to be functions, not aliases:
# Make directory and cd into it
mkcd() { mkdir -p "$1" && cd "$1" }
# Extract any archive
extract() {
case "$1" in
*.tar.gz) tar xzf "$1" ;;
*.tar.bz2) tar xjf "$1" ;;
*.zip) unzip "$1" ;;
*.gz) gunzip "$1" ;;
*.rar) unrar x "$1" ;;
*) echo "Unknown archive format: $1" ;;
esac
}
# Serve current directory over HTTP
serve() {
local port=${1:-8000}
python3 -m http.server "$port"
}
# Find and kill process on a port
killport() {
lsof -ti :"$1" | xargs kill -9
echo "Killed process on port $1"
}
# Copy last command to clipboard
clast() {
history | tail -n 2 | head -n 1 | sed 's/^ *[0-9]* *//' | pbcopy
}
Loading Aliases
After editing your config file, reload it:
source ~/.zshrc
# or
source ~/.bashrc
Or use the alias we defined: zshrc or bashrc reloads automatically.
Key Takeaways
- Keep aliases in
~/.zshrcor~/.bashrc— they load every session - For complex operations, use functions (they accept arguments)
- The git aliases save the most time —
gs,gl,ga,gcare used dozens of times daily alias rm='rm -i'is a safety net worth having always- Reload immediately:
source ~/.zshrcafter changes