mutt -s "Log" -a /path/to/*.log(.om) [email protected]
zsh glob qualifiers. While other shell globs can only generate filenames based on their name, in
zsh, you can use those qualifiers (
(.om) above), to select based on file attributes (type, size, times, permissions...) or other criteria of your own, affect the order, apply various transformations, or select a range.
In this case we use these qualifiers:
.: select only regular files.
om: order by modification time (newest first)
: select only the first one.
Note that if there are no
log files in
/path/to, the glob will fail and the command will be aborted (as you'd expect, but other shells work differently).
GNUly, the equivalent would be something like:
find /path/to -maxdepth 1 -name '*.log' -printf '%T@:%p\0' |
sort -rzg | sed -z 's/^[^:]*://;q'
[ -n "$latest" ] &&
mutt -s "Log" -a "$latest" [email protected]