Zsh Cheatsheet - Shell Configuration
After switching to Zsh, what actually speeds you up day to day is completion, history search aliases, and a custom prompt. This table covers the high-frequency .zshrc settings and common oh-my-zsh plugins and themes; back up .zshrc before editing so you always have a way back.
Basic Setup 5
chsh -s $(which zsh)Switch the default shell to zsh
source ~/.zshrcReload the config
echo $SHELLShow the current shell
setopt AUTO_CDType a dir name to cd (no cd needed)
setopt CORRECTSuggest 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]=valueDefine an associative array (hash)
Globbing & Expansion 6
**/*.jsRecursively 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
History & Search 6
HISTSIZE=10000 / SAVEHIST=10000In-memory and on-disk history size
setopt SHARE_HISTORYShare history across terminals in real time
Ctrl+RReverse incremental history search
!!Run the last command (sudo !! most used)
!$Last argument of the previous command
history -i | tailShow history with timestamps
Functions & Completion 4
function name() { ... }Define a function
alias ll="ls -la"Set an alias
autoload -Uz compinit && compinitInitialize the completion system
compdef _git g=gitReuse git completion for alias g
Prompt Customization 5
PROMPT='%n@%m %~ %# 'user@host path prompt
%n / %m / %Musername / short host / full host
%~ / %dcurrent dir (~) / absolute path
RPROMPT="%T"Right prompt shows current time
%T / %D / %W24h 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-autosuggestionsAutosuggest completions (accept with ->)
zsh-syntax-highlightingSyntax highlighting (red = error)
extract file.tar.gzextract 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
Each command links to its official documentation below, so you can verify the latest usage and read deeper.
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