I recently needed to check out a project from Subversion and then delete all of the .svn files from the project directories. Google found me a few different ways to do this, but none of them seemed to deal with a case where some of the directory and file names had spaces or quotes in them – as mine did.

After a little experimenting, I figured out the following commands could be combined as illustrated below:

From within the project root folder this command can be used to list all of the .svn directories:

$ find . -type d -name .svn

If your directory names don’t have spaces or quotes in them, then you could just pipe the find command directly into xargs and rm to delete them all:

$ find . -type d -name .svn | xargs rm -rf

If you do have spaces or quotes in your directory names, then you need to change the newlines returned from find into null characters (notice the -print0 flag), and make xargs use this to split the input into individual file names (see the -0 flag) rather than the newlines, spaces and quotes that it normally looks for:

$ find . -type d -name .svn -print0 | xargs -0 rm -fr

The above command will delete all directories named ‘.svn’, regardless of whether they have spaces, or quote characters in their names.