Using Zsh Glob Qualifiers to Replace Complex Find Pipelines
Learn how Zsh glob qualifiers let you embed file‑size,‑time and‑type tests directly in a pattern, simplifying scripts that would otherwise rely on long find pipelines.
02 Oct 2025, 20:10 UTC

The tedium of filtering files with find
When a script needs to pick files by size, age, or type, the typical approach chains find with multiple tests:
find . -name '*.pdf' -type f -mtime -1 -size -500k -print
While functional, the command becomes hard to read, especially when the logic lives inside a larger script or when you need to reuse the same filter in several places.
Zsh glob qualifiers: moving the filter into the pattern
Zsh lets you attach qualifiers directly after a glob pattern, enclosed in parentheses. The qualifiers act like predicates that are evaluated during filename expansion, so the shell returns only the matching paths.
Basic qualifier syntax
*(.)– regular files*(L+10)– files larger than 10 KiB*(m-1)– files modified less than one day ago
Multiple qualifiers are concatenated without spaces, for example *(.m-1L-500) means “regular file, modified within the last day, and smaller than 500 KiB”.
Worked example: recent PDFs under 500 KiB
Suppose you want to list all PDF files that were modified in the last 24 hours and are under 500 KiB, searching recursively from the current directory.
Enable the needed options
First turn on extended globbing and the **/ recursive glob:
setopt extendedglob globstar
Run the qualifier‑based command
print -l **/*.pdf(.m-1L-500)
Here each part means:
**/– any depth of directories (requiresglobstar)*.pdf– files ending with.pdf(.m-1L-500)– qualifier group:.– regular filem-1– modified less than 1 day agoL-500– size less than 500 KiB
If the directory contains a mix of files, the command will output only those PDFs that satisfy all three conditions.
Comparing with the traditional find approach
For reference, the equivalent find command is:
find . -name '*.pdf' -type f -mtime -1 -size -500k -print
Both forms should yield the same set of paths; the qualifier version keeps the logic inside the filename expansion, which can be easier to read when the pattern is reused.
Trade‑offs and limitations
- Portability: Qualifiers are a Zsh feature; the same command will not work in Bash or POSIX shells without invoking
zsh -cor emulation. - Version dependence: Some qualifiers (like
m-for time andLfor size) appeared in Zsh 4.2; older releases may lack them. Check withzsh --version. - Readability: Very long qualifier chains can become cryptic. Encapsulating common patterns in a function or alias helps maintain clarity.
- Globstar requirement: Recursive depth with
**/needs theglobstaroption; otherwise the pattern treats**as a literal.
Making qualifiers reusable
To avoid repeating the qualifier string, define a small function:
recent_small_pdfs() {
setopt localoptions extendedglob globstar
print -l **/*.pdf(.m-1L-500)
}
Now you can call recent_small_pdfs anywhere in your script, and change the criteria in one place.
Actionable checklist
- Start a fresh Zsh session and verify your version (
zsh --version). - Enable
extendedglobandglobstarwithsetopt. - Test the qualifier interactively in a sandbox directory containing varied files.
- Compare the output with the equivalent
findcommand to confirm correctness. - If the qualifier works, encapsulate it in a function or alias for reuse in your projects.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.