bashunixfindrm

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


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?


Solution

  • 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).