Delete files returned by find

Task: Find all files whose name contains a specific pattern and delete them.

Finding the files (or folders) is trivial using find – however, we can not simply pipe the output of find to rm because rm does not read input from standard input.

The solution is to use xargs. The example below finds all files and folders containing ".svn" and deletes them: find -name .svn -print0 | xargs -0 rm -f -r

The -print0 option of find causes each entry to be a 0-terminated string rather than EOL terminated. It is consistent with the -0 option of rm.