Recursive Globbing With globstar
Turn on ** to match files at any depth in the current directory tree.
Run shopt -s globstar then use **/*.py to match Python files recursively.
01Command
Command
$ shopt -s globstar; wc -l **/*.py02What 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
!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
- bash.1.en.html manual pageEvidence: The bash manual page documents the globstar shell option.
Last verified: 2026-10-13 · Category: Developer