Recursive Globbing With globstar

Turn on ** to match files at any depth in the current directory tree.

macOSbashautomationshellscriptingLow risk
Run shopt -s globstar then use **/*.py to match Python files recursively.

01Command

Command
$ shopt -s globstar; wc -l **/*.py

02What it does

With globstar enabled, ** expands to zero or more directories, so a recursive match fits naturally into commands like wc or cp. For interactive work it is far faster than repeatedly descending directories, and in scripts it replaces verbose find expressions when you only need matching paths.

03Risk

RiskLow risk
RequirementsmacOS default zsh/bash (bash 3.2+; some features need bash 4+ via Homebrew)
CompatibilitymacOS with bash 3.2+ (GNU bash 4+ via Homebrew for advanced features)
!Warning: Recursive globs can expand to enormous argument lists; add nullglob or use find/xargs for very large trees.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

Last verified: 2026-10-13 · Category: Developer