Putting find's -delete before -name wipes out an entire directory

A GNU findutils 4.10.0 example shows that running find with -delete placed before -name deletes everything under the target, including the directory itself, without any prompt or warning. The reason is that find evaluates its arguments as an expression from left to right, so -delete acts on each file before the name test runs. The man page explicitly warns about this ordering behavior. The safe approach is to test the command with -print first and then put -delete last on the line. The same rule applies to -exec, where filters should come first and the action last.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in