CalcSnippets Search
CLI 2 min read

`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 +7

Find files modified within the last day:

find . -type f -mtime -1

This is usually enough to answer:

  1. what old logs exist
  2. which artifacts have not been touched recently
  3. 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:

  1. preview matches
  2. refine the scope
  3. 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 +14

Then if the list looks right:

find /var/log/myapp -type f -mtime +14 -delete

Or archive instead of delete:

find /var/log/myapp -type f -mtime +14 -print

The 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.

Sources

Keep reading

Related guides