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

Another post about shell syntax!

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:

Fin

May your files be as organized as you need but not more,

—Adam


😸😸😸 Check out my new book on using GitHub effectively, Boost Your GitHub DX! 😸😸😸


Subscribe via RSS, Twitter, Mastodon, or email:

One summary email a week, no spam, I pinky promise.

Related posts:

Tags: