Zsh glob qualifiers narrow a pathname match before the command sees it. They help when a broad pattern such as *.log would include files with the wrong type or permission state, especially before cleanup or permission commands.
A qualifier sits in parentheses at the end of the pattern. (.) keeps plain files, (/) keeps directories, and (*) keeps executable plain files. Qualifiers are part of the glob, so reports/*.log(.) returns plain log files and leaves non-log files out of expansion.
The example below builds a temporary tree under /tmp/zsh-glob-demo and previews each match with print -rl --. That output is the safety check to read before reusing the same pattern with rm, chmod, or another command that changes paths.
Related: How to set Zsh shell options
Related: How to loop over files in Zsh
Steps to use glob qualifiers in Zsh:
- Create a safe workspace with separate report and archive directories.
$ mkdir -p /tmp/zsh-glob-demo/reports /tmp/zsh-glob-demo/archive
- Enter the workspace before testing relative patterns.
$ cd /tmp/zsh-glob-demo
- Create the first log file.
$ printf 'one\n' > reports/app.log
- Create the second log file.
$ printf 'two\n' > reports/db.log
- Create a non-log file beside the log files.
$ printf 'note\n' > reports/readme.txt
- Mark one log file executable.
$ chmod u+x reports/db.log
- List only plain log files.
$ print -rl -- reports/*.log(.) reports/app.log reports/db.log
The (.) qualifier keeps the match to plain files.
- List only directories in the current location.
$ print -rl -- *(/) archive reports
The (/) qualifier matches directories, so files under reports/ are not returned by this pattern.
- List executable plain files under the reports/ directory with the (*) qualifier.
$ print -rl -- reports/*(*) reports/db.log
Globs are expanded before the command runs. Preview new qualifiers with print -rl -- PATTERN before passing the same pattern to rm, chmod, or another command that changes files.
- Leave the test workspace.
$ cd /tmp
- Remove the temporary workspace.
$ rm -rf /tmp/zsh-glob-demo
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.