osx find exec rm find: exec: unknown primary or operator

freedrull picture freedrull · Jan 13, 2015 · Viewed 34.3k times · Source

I've got a bunch of files that end in "-e" that I want to remove.

$ find . -name "*-e" exec rm {} \;
find: exec: unknown primary or operator

Is the regex expanding in some way that messes everything up?

Answer

anubhava picture anubhava · Jan 13, 2015

It should be:

find . -name "*-e" -exec rm '{}' \;

Or better:

find . -name "*-e" -exec rm '{}' +

As per man find:

-exec utility [argument ...] {} +
   Same as -exec, except that ``{}'' is replaced with as many pathnames as possible for 
   each invocation of utility. This behaviour is similar to that of xargs(1).