`find -mtime` Is the File-Age Filter You Should Use Before You Start Deleting Old Builds by Hand
A practical guide to using `find -mtime` for cleanup, log rotation helpers, and build-artifact management without manually poking through old files.
Why this matters: teams waste time manually inspecting old logs, artifacts, and temp directories when the file age filter already exists and is scriptable.
If you need to find files older or newer than a certain age, find -mtime is one of the most useful low-drama tools in the shell.
Basic examples
Find files older than 7 days:
find . -type f -mtime +7Find files modified within the last day:
find . -type f -mtime -1This is usually enough to answer:
- what old logs exist
- which artifacts have not been touched recently
- what cleanup job should target
Why this is better than eyeballing timestamps
Manual cleanup is slow and error-prone. People sort by date in Finder or a GUI and still miss things or delete the wrong ones.
With find -mtime, you can:
- preview matches
- refine the scope
- add delete or archive actions later
That stepwise approach is much safer.
A safer cleanup flow
Preview first:
find /var/log/myapp -type f -mtime +14Then if the list looks right:
find /var/log/myapp -type f -mtime +14 -deleteOr archive instead of delete:
find /var/log/myapp -type f -mtime +14 -printThe point is to separate matching from destruction until you trust the pattern.
Final recommendation
If you keep managing old files manually, start using find -mtime for previews and cleanup workflows. It turns “I think these are old” into a reproducible, automatable rule.