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?
xargs
will bite unless you're careful. Usefind ... -print0 | xargs -0 ...
for example. And for deleting,find ... -delete
may be better. – Chris Davies Nov 02 '19 at 23:30