Zsh: uncover hidden files in globs with (D)

By default, Zsh globs skip hidden files and directories, meaning those with names starting with a dot. For example, in a project directory, * misses all the configuration files and directories:
$ ls -d *
README.rst generate_pigeon.py
To include them, add the (D) glob qualifier, which stands for “dot files”:
$ ls -d *(D)
.env .git .github .pre-commit-config.yaml .venv README.rst generate_pigeon.py
(ls -d lists directories themselves, rather than their contents.)
(D) never matches the special . and .. entries, so you don’t need to worry about them popping up in results.
Recursive globs
(D) matters most for recursive globs with **/, because without it, Zsh also skips hidden directories. For example, to find all YAML files in a repository:
$ ls **/*.yml
zsh: no matches found: **/*.yml
That missed the GitHub configuration files within .github. Add (D) to find them:
$ ls **/*.yml(D)
.github/dependabot.yml .github/workflows/main.yml
Sometimes skipping hidden directories is what you want, though. For example, **/*.py matches only generate_pigeon.py, usefully skipping the virtual environment in .venv, while **/*.py(D) includes all its files.
Check out my new book Boost Your GitHub DX.
One summary email a week, no spam, I pinky promise.
Related posts:
- Zsh: find the largest files with the
(OL)glob qualifier - Zsh: tab complete glob qualifiers
- Zsh: sort globs in natural order with the
(n)glob qualifier
Tags: zsh