I would expect the following command to delete all files with extension .x or .z, but instead it seems to only delete the first file listed:

mkdir foo
touch foo/{a.x,b,c.z}
find foo -type f -name '*.x' -o -name '*.z'  # correctly lists a.x and c.z
find foo -type f -name '*.x' -o -name '*.z' -exec rm -f {} \+  
    # only deletes c.z

Why is this happening?

  • @steeldriver You are right, thanks for the link. I think I will just start using xargs instead of exec, so many hidden tricks.. – Jonathan H Nov 2 '19 at 23:18
  • 1
    xargs will bite unless you're careful. Use find ... -print0 | xargs -0 ... for example. And for deleting, find ... -delete may be better. – roaima Nov 2 '19 at 23:30

Browse other questions tagged or ask your own question.