Linux – How to remove files containing whitespace recursively

bashlinuxrecursion

I'm having some trouble with this command under bash in Ubuntu:

rm $(find . -name "*.exe")

My aim is to remove, recursively, all files ending in .exe. But some files have white spaces and this breaks the command.

Any suggestions on how to approach this problem?

Best Answer

find . -name "*.exe" -exec rm -f '{}' +

This has find format the command and arguments, and it carefully avoids mangling the names (by passing each one as a separate argument to rm). The '+' means "do as many as you can reasonably in one execution of rm".

Related Question