Terminal GuideTerminal Guide

Zsh

Z Shell

Feature-rich shell with excellent tab completion and plugin ecosystem

POSIX CompliantReleased: 1990Official Site

Overview

Zsh (Z Shell) is a powerful shell that combines features from bash, ksh, and tcsh. Since macOS Catalina, it has been the default shell on macOS. Zsh is known for its excellent interactive features, extensive customization options, and the popular Oh My Zsh framework.

Quick Facts

Full NameZ Shell
CategoryModern
POSIX CompliantYes
Config File.zshrc
Default OnmacOS (Catalina and later), Kali Linux
First Release1990

Who Should Use Zsh?

  • Power users - Advanced tab completion and globbing
  • macOS users - Default shell since Catalina
  • Customization enthusiasts - Themes and plugins via Oh My Zsh
  • Developers - Git integration and productivity features

Installation

Install and configure Zsh.

bash
# Install on macOS (pre-installed on Catalina+)
brew install zsh

# Install on Debian/Ubuntu
sudo apt install zsh

# Install on Fedora
sudo dnf install zsh

# Set as default shell
chsh -s $(which zsh)

# Install Oh My Zsh (optional but recommended)
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Basic Usage

Zsh-specific features and syntax.

bash
# Extended globbing
ls **/*.txt          # Recursive glob
ls *(.)              # Only files
ls *(/)              # Only directories

# Array slicing
arr=(a b c d e)
echo $arr[2,4]       # b c d

# Parameter expansion
name="hello"
echo ${(U)name}      # HELLO (uppercase)
echo ${(C)name}      # Hello (capitalize)

# Spelling correction
setopt CORRECT
# Zsh will suggest corrections for typos

Configuration

Zsh configuration and customization.

bash
# ~/.zshrc configuration

# Oh My Zsh settings
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="robbyrussell"
plugins=(git docker kubectl)
source $ZSH/oh-my-zsh.sh

# Custom prompt (without Oh My Zsh)
PROMPT='%F{green}%n@%m%f:%F{blue}%~%f$ '

# Enable features
setopt AUTO_CD          # cd by typing directory name
setopt HIST_IGNORE_DUPS # Ignore duplicate history
setopt SHARE_HISTORY    # Share history between sessions

Key Features

Advanced Tab Completion

Context-aware completion with descriptions and menus

Extended Globbing

Powerful pattern matching like **/*.txt for recursive search

Oh My Zsh

Huge ecosystem of themes and plugins

Spelling Correction

Automatic correction suggestions for typos

FAQ

Should I use Oh My Zsh?

Oh My Zsh is great for beginners and provides easy access to themes and plugins. However, it can slow down shell startup. Consider lightweight alternatives like zinit for better performance.

Is Zsh compatible with Bash scripts?

Zsh is largely compatible with Bash scripts, but there are differences. Use "emulate bash" in Zsh or add "#!/bin/bash" shebang to ensure Bash execution.

Summary

Key takeaways for Zsh:

  • Default shell on macOS with excellent interactive features
  • Advanced tab completion and globbing
  • Rich plugin ecosystem via Oh My Zsh
  • POSIX compatible with many extensions

Official Documentation

For authoritative information, refer to the official documentation:

Written by Dai AokiPublished: 2026-01-20

Related Articles