How to Fix “find … -delete” Going on the Wrong Directory by Adding a Safety Check with `-maxdepth` and `-mindepth`

The “find … -delete” Catastrophe and How to Stop It

A single typo in a find command can wipe a production directory, a backup, or an entire filesystem. The classic recipe that trips even seasoned sysadmins is:

find / -name '*.tmp' -delete

If the leading slash is omitted or the pattern is too broad, the command starts at the wrong root and deletes everything that matches. In 2025, a handful of high‑profile incidents were traced back to this exact mistake, underscoring that defensive scripting is as much about guardrails as it is about automation.

[Read More]