How to recursively delete files and directories (*.svn) with find and xargs
Every once in a while, I want to delete some files from a set of directories. Under windows you do a file search, select everything with CTRL-A and delete. It is every bit as simple under Linux and OS X.
For example, let's say you want to tar up or merge directories that are checked out of a subversion repository. If you just tar up the files, you will have extra copies of every single file making the tarball needlessly large. Not good. Or maybe you want to delete those .DS_Store files that OS X craps all over your hard drives.
Here's how to do it. Use the find command to find the .svn directories and pipe the output to the xargs utilities to merge the output into something the rm command can use. This can be used to quickly delete other files patterns, but be very careful (for obvious reasons):
1: rm -rf `find . -name "*.svn" | xargs`
Simple.