Learn Zsh

Interactive shell with powerful completion, globbing and customization

13 lessons · 2 hours · 4 levels · covers Zsh 5.9

Zsh is a Bourne-style Unix shell, largely compatible with bash, that adds a programmable completion system, rich globbing, a highly configurable line editor and prompt, and a large plugin ecosystem. It has been the default shell on macOS since Catalina, and many developers on Linux adopt it for a faster, friendlier terminal. Learning it well means fewer keystrokes every day and a shell configuration you understand rather than copy-paste.

Before you start

Zsh builds on these; the tree links to the exact lessons you need.

How deep do you want to go?

1. EssentialsRead and write simple code, do the everyday basics4 lessons · 33 min in total
2. PracticalUse it productively at work, with the usual idioms7 lessons · 1 hour in total
3. AdvancedThe less common features, performance and trade-offs10 lessons · 2 hours in total
4. ExpertInternals and the edge cases experts know13 lessons · 2 hours in total

The Zsh tree

ZshZsh vs bash, and switchingZsh vs bash, andswitchingStartup files: .zshenv, .zprofile, .zshrcStartup files:.zshenv, .zprofile, .…Tab completionTab completionRecursive globs and qualifiersRecursive globs andqualifiersOptions and shared historyOptions and sharedhistoryCustomizing the promptCustomizing thepromptPlugins, frameworks and aliasesPlugins, frameworksand aliasesThe shell and running commandsThe shell and runningcommandsVariablesVariablesfor and while loopsfor and while loops
Essentials and Practical shown (7 of 13 lessons); the full list is below. Click a lesson to read it.

All 13 lessons, in order

Setup and configuration

  1. Zsh vs bash, and switching · Essentials · 7 min

    What zsh adds over bash, how to check which shell you are in and how to make zsh your login shell.

  2. Startup files: .zshenv, .zprofile, .zshrc · Essentials · 9 min

    Which zsh config file is read when, and what belongs in each one.

  3. Options and shared history · Practical · 10 min

    Turn zsh behaviour on and off with setopt, and configure a large, shared, de-duplicated history.

  4. Customizing the prompt · Practical · 10 min

    Build a prompt with % escapes, colours, exit-status conditionals and the git branch via vcs_info.

Interactive power

  1. Tab completion · Essentials · 8 min

    Turn on zsh's completion system, get a navigable menu and complete options, branches, hosts and paths.

  2. Plugins, frameworks and aliases · Practical · 10 min

    Add autosuggestions and syntax highlighting, choose between a framework and plain sourcing, and use global and suffix aliases.

  3. The line editor (ZLE) and custom widgets · Advanced · 12 min

    Configure key bindings with bindkey, use prefix history search and write your own ZLE widgets.

  4. Writing completions with compsys · Expert · 15 min

    Write a _command completion function with _arguments and _describe, register it via fpath and tune it with zstyle.

Globbing

  1. Recursive globs and qualifiers · Essentials · 9 min

    Use ** for recursive matching and glob qualifiers like (.), (/) and (om) to filter and sort files.

  2. Qualifiers, modifiers and extended globs · Advanced · 12 min

    Filter files by size, age and owner, transform paths with :t :h :r :e and use ^ and ~ with EXTENDED_GLOB.

Scripting and internals

  1. Scripting differences from bash · Advanced · 12 min

    No word splitting, 1-based arrays, typeset -A, last pipe stage in the current shell, and emulate for compatibility.

  2. Parameter expansion flags · Expert · 14 min

    Split, join, sort, deduplicate, change case and search arrays with ${(flags)name} and subscript flags.

  3. Autoloaded functions and startup speed · Expert · 12 min

    Organise functions with fpath and autoload, profile startup with zprof and speed it up with caching and lazy loading.