Problem using xargs with rm

I am trying to call xargs, however rm is complaining

find . -maxdepth 1 -name "*tests*" -print0 | xargs -0 rm
rm: missing operand
Try `rm --help' for more information.
find . -maxdepth 1 -name "*tests*" -print0 | xargs -0 -I {} rm {}
1 Like

It's because your find doesn't return any filename. Try either:

xargs -r0 rm

Or directly:

find ... -delete

if your find implementation supports it.
Or:

find ... -exec rm {} +
1 Like

Ruby

ruby -e 'Dir["*tests*"].each {|x| File.delete(x) }'