Plainnotes

Cleaning old files with find, without the -mtime mistake

2025-10-29 · 2 min readTools

Cleaning files older than a week with find /tmp -mtime 7 -delete also removed recent ones: -mtime 7 means exactly seven days, not older than seven.

The correct form is -mtime +7.

Details that matter. -delete implies -depth but still fails on non-empty directories, so add -type f. Always -print first and swap in -delete once the list looks right — the only reliable dry run. -mmin counts minutes; -atime is unreliable under relatime.

And since -delete never asks, an empty variable in the path can target the wrong tree. Use absolute paths and test.

find /var/tmp -type f -mtime +7 -print