zsh globbing qualifiers
Globbing is the term for pattern matching that shells use to expand wildcards like * or ?. In zsh, globbing patterns can be followed by a list of qualifiers inside of parenthesis, which restrict the filenames that match the glob.
For example, here are a few globs with simple modifiers:
# . modifier means all "plain files"
% ls *(.)
foo.txt bar.jpg
# * modifier means all "executable plain files"
% ls *(*)
a.out
Normally, the * wildcard would match and expand to all files in the directory (except hidden dot-files). However, with a modifier specified in parens after the glob, you can qualify or restrict your glob.
Besides filtering, you can also specify sorting qualifiers:
oc — sort by criteria c ascending. Oc — sort by criteria c descending.
Where criteria c
can be:
n name (default) L size (length) of file a access time m modification time c creation time
Here is the magic, qualifiers can actually be indexed with square braces of the
form [beg[,end]]
. For example, you can get the most recently modified file:
# glob for the newest file by modification
% ls -lha *(om[1])
quux
# glob for the oldest file by modification
% ls -lha *(Om[1])
a.out
http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Qualifiers