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.

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
Mark F's Gravatar Linux can be confusing at times, while it's amazing for server related tasks.. the complexity of simple commands is why I love keeping a Windows VPS for the more simple tasks
# Posted By Mark F | 2/27/12 12:56 AM
Edward Beckett's Gravatar Barney's answer is the one I'd recommend the most ...

find ./ mixed with rm -rf is a pretty dangerous proposition ... ;-)

I use this style alot ...

find . -type d -name \*.svn -print0 | xargs -0 -exec rm -f {} \;

Here's a really good way to find stuff recursively too ... Gives you the file name and line number ...

find . -name 'thefile' | xargs grep -n {} \;
# Posted By Edward Beckett | 8/31/12 10:49 PM
Masterpiece's Gravatar It is useful in many others Masterpiece,while it's amazing for server related tasks. Here's a really good way to find stuff recursively too .Nice Watch for men and ladies ! .
# Posted By Masterpiece | 3/3/15 9:37 PM
wordpress on ubuntu's Gravatar Thanx.. will try it Out..
# Posted By wordpress on ubuntu | 9/22/18 1:23 AM
shopic soe's Gravatar Hi there. what's the battery life on the laptop if we are running a server OS ? is it the same as when a client OS is present?
# Posted By shopic soe | 11/12/18 4:33 AM
apple account recovery's Gravatar If you don't have a valid iOS provisioning profile and certificate pair, Sidekick can automatically generate them for you with a free Apple account.
# Posted By apple account recovery | 11/12/18 4:35 AM price's Gravatar With the teacher training plans, we can create able instructors who will help progress success of the learning. The primary teacher education programs for the basic schools and colleges of education only until quite recently.
# Posted By price | 12/18/18 5:04 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.1. Contact Blog Owner