Deleting .svn folders recursively on OS X and Linux

Here is a handy tidbit that I came across while I was switching some of my projects from SVN to Git.


find ./ -name .svn -exec rm -rf '{}' ';'

While in the project's root folder, when you run this it will delete any .svn folders that it finds in the project folder and any of its subfolders. This made removing the SVN version control quite simple without having to run an SVN export on every project and make copies of all of them.

Mostly I am blogging this so that I have it for my own reference, but I thought others might find it useful too.

I am no expert on bash command line scripts, so I won't pretend to understand exactly what is going on here, but it seems obvious that this script will do a find on the current folder and its subfolders for any folder/file named '.svn' and run 'rm -rf' on if. The -rf attributes tell the rm command to recursively force-delete any folders and its children. This is needed since .svn matches we'll be finding are directories.

Be careful when running this, it will NOT ask you if you are sure. Of course, this will work with other files and folders as well. Like if you want to delete all of those .DS_Store files that OS X likes to stick everywhere.


find ./ -name .DS_Store -exec rm '{}' ';'

Since .DS_Store files are not directories, the -rf options are not needed.

Comments
Emma Goodwin's Gravatar I normally just use:

rm -rf `find -type d -name .svn` .

It does the same thing, it's just a bit shorter :)
# Posted By Emma Goodwin | 1/3/12 10:36 AM
Jason Dean's Gravatar Thank you Emma. I will try that out.
# Posted By Jason Dean | 1/3/12 10:44 AM
Barney Boisvert's Gravatar Another option is `find -name .svn | xargs rm -rf`

This has the advantage of allowing you to run the `find` command by itself, and then tack on the `rm` when you're satisfied it's returning the right list of files. It also allows you to post-process the find result, which isn't necessary in this case, but is useful in many others (e.g., `find -name .svn | grep -v '/external-subproject-to-keep-svn/` | xargs rm -rf`).
# Posted By Barney Boisvert | 1/3/12 11:50 AM
Jason Dean's Gravatar Thanks Barney. I gotta admit, grep confuses the shit outta me. It's like they *tried* to make it hard to use.

Great tip though.
# Posted By Jason Dean | 1/3/12 12:07 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.1. Contact Blog Owner