A Unix Command to Recursively Delete all .svn Folders
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.

February 18, 2010 - 4:25 pm
I’ve never really figured out xargs, so the version of the find command i use is this: find . -name .svn -exec rm -f {} \;
The braces cause the file name and path to be inserted, then you need to semicolon (escaped) to end the command. Another good variation on this is using grep. “grep -H” will put out the file name.
HTH, Mark
February 18, 2010 - 6:24 pm
Nice one! Thanks for that Mark I’ll try it out next time I’m zipping a project for someone.
February 26, 2010 - 10:54 am
Nice post !! really helpful.