Zsh Cheatsheet - Shell Configuration

All essential Zsh commands organized by use case, with 37+ entries you can copy and run directly. Find the right command fast when you need it.

SysOps·37 commands·Last updated 2026-07-21
Back to SysOps

Basic Setup 5

chsh -s $(which zsh)
Switch the default shell to zsh
source ~/.zshrc
Reload the config
echo $SHELL
Show the current shell
setopt AUTO_CD
Type a dir name to cd (no cd needed)
setopt CORRECT
Suggest corrections on typo

Variables & Arrays 6

NAME="value"
Define a variable (no spaces around =)
arr=(a b c)
Define an array (zsh indexes from 1)
echo $arr[1]
Access the first array element
echo ${arr[@]}
Access all array elements
${#arr[@]}
Get array length
typeset -A dict\ndict[key]=value
Define an associative array (hash)

Globbing & Expansion 6

**/*.js
Recursively match .js in subdirs
*.{js,ts}
Brace expansion, multiple suffixes
*(.)
Match regular files only (glob qualifier)
*(/)
Match directories only
*(om[1])
The most recently modified file
=ls
= expands to the command's full path

Functions & Completion 4

function name() { ... }
Define a function
alias ll="ls -la"
Set an alias
autoload -Uz compinit && compinit
Initialize the completion system
compdef _git g=git
Reuse git completion for alias g

Prompt Customization 5

PROMPT='%n@%m %~ %# '
user@host path prompt
%n / %m / %M
username / short host / full host
%~ / %d
current dir (~) / absolute path
RPROMPT="%T"
Right prompt shows current time
%T / %D / %W
24h time / date / month-day-year

oh-my-zsh & Plugins 5

plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
Enable a plugin list
ZSH_THEME="robbyrussell"
Set a theme (random to rotate)
zsh-autosuggestions
Autosuggest completions (accept with ->)
zsh-syntax-highlighting
Syntax highlighting (red = error)
extract file.tar.gz
extract plugin auto-detects archive format

Tips

  • Install oh-my-zsh: sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  • zsh-autosuggestions needs a separate install (git clone into $ZSH_CUSTOM/plugins).
  • setopt AUTO_CD lets you cd by typing a dir name.
  • Bind up/down arrows to prefix history search via bindkey.
  • zsh arrays start at 1 (bash starts at 0) - mind this when porting scripts.
  • ZDOTDIR changes the config dir, handy for isolated configs.

Official References

Commands are compiled from the official docs below. Click to verify the latest usage.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us