tl;dr: -delete
is not required by POSIX, -exec
is.
Facts
POSIX 1003.1 man page for find
specifies -exec
but not -delete
.
This means -exec
should work virtually everywhere. I would be surprised finding find
that has -delete
without -exec
. The opposite is quite possible. Especially lightweight systems that use busybox
tend to provide basic command line options only.
E.g. I have an OpenWRT on one of my routers and its find
understands -exec
, it doesn't understand -delete
.
Not having -delete
is not a big deal when you have -exec rm …
. On the other hand -delete
cannot replace -exec
in general. It's a wise design to allow omitting -delete
first.
Personal experience, observations and opinions
The above should be the primary reason why -exec rm {} \;
is so widely recommended. The secondary may be a snowball effect. Users read articles and examples, get familiar with -exec
and publish their own commands (e.g. here on Super User). Some of them may not even know -delete
exists.
Few times I have seen (or given) remarks like 'You can use -delete
instead'. And the responses were like 'Thanks, I didn't know that'. I don't remember any response 'I know, but this is not POSIX'.
Having said all this I tend to mention -delete
whenever -exec rm {} \;
appears. The reason is -delete
doesn't spawn a new process, while -exec rm {} \;
invokes a separate rm
for each matched file. If you cannot use -delete
then your next thought should be -exec rm {} +
that can remove multiple files with a single rm
(still it will invoke rm
more than once if needed).
Why isn't -exec … +
widely recommended then? It might be because of its limitations. I can imagine an inexperienced user thinking 'This works with rm
, let me use it with mv
!' Then -exec mv {} foo/ +
doesn't work because {}
needs to be at the end, just before +
. The user gets frustrated and runs back to mama Windows.
Recommending -delete
is usually safe here on Super User, I think. Most questions specify "big" OS-es, find
commands there are rich with options. And even if there's a user whose find
is limited I will probably get feedback. He or she says the solution doesn't work for them and I suggest -exec rm …
instead, explain the issue etc.
A standalone article that recommends -delete
won't get such feedback. In case of any trouble a user will simply go to the next link returned by Google.