find -mtime: Prune Files by Age in Days
find -mtime selects files by how many days ago they were last modified.
Time-based pruning keeps caches and artifact stores from growing forever. -mtime +N is the workhorse for "older than N days".
What it does
find -mtime N matches files modified exactly N 24-hour periods ago. +N means more than N days ago (older), and -N means less than N days ago (newer). The count is in whole 24-hour units measured from now, not calendar days.
Common usage
find /cache -type f -mtime +7 -delete # older than 7 days
find . -type f -mtime -1 # changed in last 24h
find /tmp -type f -mtime +30 -printOptions
| Expression | What it does |
|---|---|
| -mtime +N | Modified more than N days ago (older) |
| -mtime -N | Modified less than N days ago (newer) |
| -mtime N | Modified exactly N days ago (a 24h window) |
| -atime / -ctime | Same scheme for access / inode-change time |
| -daystart | GNU: measure from the start of today, not now |
In CI
The unit is 24-hour periods from the current time, so -mtime +7 means "at least 8 full days old" because of how the rounding works. For calendar-day boundaries on GNU find, add -daystart before -mtime. For finer windows use -mmin.
Common errors in CI
A prune that deletes nothing usually used -mtime 7 (exactly day 7) when +7 (older than) was meant. -daystart is GNU only and must come before the time test; BSD/macOS find lacks it, so use -mtime with -newer against a reference file instead.