To create an alias, add it to your .zshrc file:

echo 'alias ll="ls -la"' >> ~/.zshrc
source ~/.zshrc

Now typing ll runs ls -la.

How Aliases Work

An alias is a shortcut. Instead of typing a long command, you type a short word.

You type What runs
ll ls -la
gs git status
projects cd ~/Projects

Creating Your First Alias

Step 1: Open your shell config

nano ~/.zshrc

Step 2: Add your alias

Add a line like this at the end of the file:

alias ll="ls -la"

Step 3: Save and exit

Press Control + O, then Enter to save. Press Control + X to exit.

Step 4: Reload the config

source ~/.zshrc

Your alias is now active.

The One-Line Method

Add aliases without opening a text editor:

echo 'alias gs="git status"' >> ~/.zshrc && source ~/.zshrc

This appends the alias to your config and reloads it immediately.

Useful Aliases to Steal

# Navigation
alias ..="cd .."
alias ...="cd ../.."
alias home="cd ~"
alias projects="cd ~/Projects"
alias downloads="cd ~/Downloads"

# Listing files
alias ll="ls -la"
alias la="ls -A"
alias l="ls -CF"

# Git shortcuts
alias gs="git status"
alias ga="git add ."
alias gc="git commit -m"
alias gp="git push"
alias gl="git log --oneline -10"

# Safety nets
alias rm="rm -i"
alias cp="cp -i"
alias mv="mv -i"

# Shortcuts
alias c="clear"
alias h="history"
alias edit="nano"

# Mac-specific
alias showfiles="defaults write com.apple.finder AppleShowAllFiles YES && killall Finder"
alias hidefiles="defaults write com.apple.finder AppleShowAllFiles NO && killall Finder"
alias flushdns="sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder"

Aliases with Arguments

Basic aliases don't accept arguments. For that, use a function:

# This won't work as expected:
alias greet="echo Hello \$1"  # \$1 is empty when alias is defined

# Use a function instead:
greet() {
    echo "Hello \$1"
}

Add functions to your .zshrc the same way as aliases.

View Your Current Aliases

To see all defined aliases:

alias

To check a specific alias:

alias ll

Remove an Alias

Temporarily (current session only)

unalias ll

Permanently

Edit your .zshrc and delete the line, then:

source ~/.zshrc

Override a Built-in Command

You can alias over existing commands:

alias ls="ls -G"    # Always colorize ls output
alias grep="grep --color=auto"

To run the original command instead of your alias, use a backslash:

\ls    # Runs the real ls, not your alias

Check If an Alias Exists

Before creating an alias, check if the name is already used:

type ll

This tells you if ll is an alias, function, or command.

Common Mistakes

Forgetting to source: After editing .zshrc, you must run source ~/.zshrc or open a new Terminal window.

Spaces around the equals sign: Wrong: alias ll = "ls -la". Right: alias ll="ls -la". No spaces.

Using single quotes when you need double: Use double quotes if you want variables to expand when the alias runs. Single quotes are literal.

Overriding something important: Don't alias over critical commands like cd or sudo without knowing what you're doing.

Where Aliases Are Stored

Shell Config file
zsh (default on modern Mac) ~/.zshrc
bash ~/.bash_profile or ~/.bashrc

Check your shell with echo \$SHELL.


Keep Learning

Aliases are one way to reduce typing and make Terminal work for you. The free course covers this and more productivity techniques.

Check it out at Mac Terminal for Humans.