0

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?

Jonathan H
  • 2,373
  • @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 02 '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. – Chris Davies Nov 02 '19 at 23:30

0 Answers0