Zsh: list recently modified files with (m0) glob qualifiers

My downloads directory is a junk pile that I just never get around to fully clearing. So if I’ve just downloaded a bunch of files, I normally want to work with them and ignore the rest of the files.
To do this, I’ve found it convenient to have Zsh select recently modified files with glob qualifiers, the extra syntax you can add to filename globs.
The m qualifier selects files by modification time, measured in whole days by default. So m0 matches files modified zero whole days ago, that is, within the past 24 hours:
$ ls -ld *(m0)
-rw-r--r-- 1 me staff 289345021 Aug 4 09:12 I rode the world's fastest train.mp4
-rw-r--r-- 1 me staff 174562903 Aug 4 12:41 The world's cleanest railway.mp4
To limit to the last hour, add the h unit specifier before the number, making the check count whole hours instead of days:
$ ls -ld *(mh0)
-rw-r--r-- 1 me staff 174562903 Aug 4 12:41 The world's cleanest railway.mp4
The other available units are M (months), w (weeks), m (minutes), and s (seconds).
Some extra tricks:
Use the recursive glob
**/*to search subdirectories too:$ ls -ld **/*(m0)
Add the
.qualifier to select only plain files, excluding directories that merely contain a recently modified file:$ ls -ld **/*(.m0)
Add the
Nqualifier to make the glob expand to nothing instead of erroring when there are no matches, useful in scripts:$ ls -ld *(.m0N)
😸😸😸 Check out my new book on using GitHub effectively, Boost Your GitHub DX! 😸😸😸
One summary email a week, no spam, I pinky promise.
Related posts:
Tags: zsh