Updated November 2026: Added sections on aliases with arguments (use a function) and where to put your aliases, refreshed all examples and verified them in zsh 5.9.

My shell is the first program I start in the morning and the last one I close in the evening, so I tweak it regularly. Aliases are the easiest way to start: they save keystrokes on the commands you type all day.

I use Docker, Kubernetes, and Microsoft Azure every day, so most of my aliases support those tools. Yours will look different. The point is to find the commands you type over and over and make them shorter.

In this post I show the five types of aliases I use in ZSH, how to handle aliases that need arguments, and where to put them.

Where to Put Your ZSH Aliases

Put your aliases in ~/.zshrc. ZSH reads that file whenever it starts an interactive shell, so every new terminal tab picks them up.

Once the list grows, I move the aliases into a separate file and source it from ~/.zshrc:

BASH
# ~/.zshrc
[[ -f ~/.zsh_aliases ]] && source ~/.zsh_aliases

After editing either file, reload the configuration in your current shell:

BASH
# re-read ~/.zshrc in the current shell
source ~/.zshrc

# or replace the current shell with a fresh one
exec zsh

source keeps your session and re-runs the file on top of it. exec zsh starts clean, which is handy when you removed an alias and want it gone for good.

A few commands help when you work with aliases:

BASH
alias          # list all aliases
alias k        # show a single alias
unalias k      # remove an alias from the current shell
\ls            # run the original command, bypassing an alias named ls

Simple Aliases

Simple aliases are the starting point. The definition follows the alias name="command" pattern (no spaces around =).

BASH
# navigation aliases
alias dev="cd ~/dev/"
alias personal="cd ~/dev/thorstenhans"

# kubectl aliases
alias k="kubectl"
alias kgx="kubectl config get-contexts"

# docker aliases
alias d="docker"
alias dps="docker ps"

With those aliases in my ~/.zshrc, I jump to frequently used directories and fire up common commands with a few keystrokes.

Suffix Aliases

Suffix aliases are defined with the -s flag. They open files with a specific extension in a tool of your choice when you type just the file name. The pattern is alias -s extension=tool. The samples assume VS Code is installed and available as code.

BASH
# Azure CLI files
alias -s azcli=code

# Markdown files
alias -s md=code

# JSON files
alias -s json=code

# several extensions at once
alias -s {cs,ts,html}=code

Reload your ~/.zshrc and try it:

BASH
echo "# Hello World" > sample.md

# type the name of the file and hit ENTER
sample.md

ZSH turns sample.md into code sample.md, and VS Code opens the file.

Global Aliases

Global aliases are defined with the -g flag. A regular alias only expands at the start of a command. A global alias expands anywhere in the command line. The pattern is alias -g NAME="text".

BASH
# I ask Azure for resource IDs all the time
alias -g qId="--query id -o tsv"

# pipe into grep
alias -g G="| grep"

Compare the full command with the one using the global alias:

BASH
# full command to query the ID of an AKS cluster
az aks show -n myaks -g rg-demo --query id -o tsv

# same command with the global alias
az aks show -n myaks -g rg-demo qId

# global aliases work in pipes too
docker ps G nginx

Because they expand everywhere, pick names you never type as regular words. Uppercase names like G are a common convention.

ZSH Alias With Arguments: Use a Function

Aliases can’t take arguments. ZSH replaces the alias name with its text and appends whatever you typed after it. $1 inside an alias doesn’t refer to anything:

BASH
alias greet='echo "Hello, $1!"'
greet Thorsten
# Hello, ! Thorsten

When you need arguments, or need them somewhere other than the end, write a shell function. It goes into ~/.zshrc just like an alias and you call it the same way:

BASH
greet() {
  echo "Hello, ${1:-stranger}!"
}

greet Thorsten   # Hello, Thorsten!
greet            # Hello, stranger!

Inside the function, $1, $2, … are the positional arguments, $@ is all of them as separate words and $* is all of them as one string. Two functions I use a lot:

BASH
# create a directory and change into it
mkcd() {
  mkdir -p -- "$1" && cd -- "$1"
}

# commit with a message without typing quotes
gcm() {
  git commit -m "$*"
}

For example, to list the AKS clusters in a resource group in a given output format:

BASH
getaks() {
  az aks list -g "$1" -o "${2:-table}"
}

getaks rg-demo        # table output
getaks rg-demo jsonc  # colored JSON

One gotcha: if a name is already an alias, ZSH refuses to define a function with the same name (defining function based on alias). Run unalias greet first, or remove the old alias from your ~/.zshrc before you add the function.

Operating System Specific Aliases

This isn’t a separate alias type, but it matters once you use the same dotfiles on more than one platform. I use macOS daily and Linux in GitHub Codespaces and containers. A simple check on $OSTYPE keeps platform-specific aliases where they belong:

BASH
if [[ $OSTYPE == darwin* ]]; then
  # macOS
  alias flushdns="sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder"
  alias browse="open -a 'Google Chrome'"
  alias azure="browse https://portal.azure.com"
elif [[ $OSTYPE == linux* ]]; then
  # Linux
  alias open="xdg-open"
fi

This is how my macOS-specific aliases looked:

Platform-specific ZSH aliases for macOS

Aliases to Edit and Reload .zshrc

Two aliases I use all the time: ec opens ~/.zshrc in my editor and sc reloads it.

BASH
# open ~/.zshrc in the editor set in $EDITOR
alias ec="$EDITOR $HOME/.zshrc"

# reload ~/.zshrc
alias sc="source $HOME/.zshrc"

Note the double quotes: $EDITOR is expanded when the alias is defined. Set EDITOR before this line in your ~/.zshrc, or use single quotes to expand it when you run ec.

Conclusion

Simple, suffix, and global aliases, functions for everything that needs arguments, and a few if blocks for platform-specific bits cover everything I need in my shell. Look at the commands you type every day and start with two or three aliases.

If you present at conferences or meetups, explain the aliases you will use at the start of your talk. Maybe your audience uses kc instead of k for kubectl.

Special thanks to Sundeep Agarwal for pointing me to some typos and to simohamed for the tip regarding bulk association for suffix aliases.