Terminal Aliases
Create shortcuts for long or frequently used terminal commands
An alias is a shortcut for a command you type often. Instead of typing out git status every time, you could type gs. Instead of a long SSH command to a server, you type myserver. Aliases save time and reduce typos – once you start using them, you'll wonder how you lived without them.
macOS uses zsh by default, so aliases go in your ~/.zshrc file.
Creating a temporary alias
This lasts only until you close the terminal:
alias ll='ls -la'
Now typing ll runs ls -la. Useful for testing before making it permanent.
Making aliases permanent
Open your shell config file:
nano ~/.zshrc
Add your aliases anywhere in the file:
alias ll='ls -la'
alias gs='git status'
alias gp='git push'
alias gc='git commit -m'
Save (Ctrl + O, Enter, Ctrl + X), then reload:
source ~/.zshrc
Useful alias ideas
Navigation shortcuts:
alias desktop='cd ~/Desktop'
alias projects='cd ~/Projects'
alias ..='cd ..'
alias ...='cd ../..'
Git shortcuts:
alias gs='git status'
alias ga='git add .'
alias gc='git commit -m'
alias gp='git push'
alias gl='git log --oneline'
alias gd='git diff'
Safety aliases (ask before destructive actions):
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
These prompt you for confirmation before deleting, overwriting, or moving files.
Convenience:
alias cls='clear'
alias h='history'
alias ports='lsof -i -P -n | grep LISTEN'
alias myip='curl -s ifconfig.me'
Aliases with arguments (functions)
Regular aliases can't take arguments in the middle. For that, use a function:
mkcd() {
mkdir -p "$1" && cd "$1"
}
Add this to ~/.zshrc. Now mkcd new-project creates a directory and moves into it.
Organizing aliases in a separate file
If you have a lot of aliases, keep them in their own file:
- Create
~/.aliases:
nano ~/.aliases
- Put your aliases there
- Add this line to
~/.zshrc:
source ~/.aliases
Viewing your current aliases
alias
This lists every alias currently set. To check a specific one:
alias gs
Removing an alias
For the current session:
unalias gs
To remove it permanently, delete the line from ~/.zshrc and run source ~/.zshrc.
Frequently Asked Questions
Will my aliases override real commands?▾
Yes. If you alias rm to rm -i, the alias takes priority over the bare rm command. To run the original command without the alias, prefix it with a backslash: \rm file.txt. This bypasses the alias for that one invocation.
Why isn't my alias working after I added it?▾
You need to reload your shell config after editing it. Run source ~/.zshrc (Mac), source ~/.bashrc (Linux), or . $PROFILE (PowerShell). Or just close and reopen your terminal.
Can I share aliases between bash and zsh?▾
Yes. Put your aliases in a separate file like ~/.aliases and source it from both ~/.bashrc and ~/.zshrc with source ~/.aliases. The alias syntax is identical between bash and zsh.
Is there a limit to how many aliases I can have?▾
No practical limit. Power users often have dozens or even hundreds. If your list gets long, organizing them in a separate file keeps things tidy. Just make sure alias names don't conflict with commands you actually need.
How do I see what command an alias runs?▾
Run alias name (Mac/Linux) or Get-Alias name (PowerShell) to see the definition. On Mac/Linux you can also use type name or which name to see if something is an alias, function, or program.