Recursively remove .svn files

Dec 16, 2005

Here’s a quick shell script to recursively remove all the the .svn files starting in the current directory and working down. find . -type f -name "*.svn" -exec rm '{}' \; -print Change .svn to look for different types.

Comments:

Mike - Sep 5, 2007

This creates a “Run Shell Script” that never goes away in my title bar… Are you sure this is doesn’t end up looping?


Simon - Dec 2, 2007

Mike - not sure how you’ve run the script but it’s always been fine for me. Have you any other details. Hardwarerocks - Thanks for the info, the man page for find on my install (OS X Tiger) doesn’t mention that -d is deprectated. However I’ve changed the post accordingly.


Hardwarerocks - Sep 2, 2007

The code above will not work.. Error.. warning: the -d option is deprecated; please use -depth instead, because the latter is a POSIX-compliant feature. This one works.. find . -type f -name “*.svn” -exec rm ‘{}’ \; -print


Akshay Surve - Feb 6, 2008

The semicolon afer .svn is missing. - Akshay


David - Feb 4, 2008

The .svn ‘files’ in question are folders which contain the subversion meta-data, including the pristine copies of the checked-out files of your working tree; deleting them means the tree can’t be used as a subversion working tree. I’m puzzled that you would want to treat an svn working tree this way, unless you specifically want a checked-out copy of the repository without the .svn folders. That’s what ‘svn export’ is for.


Simon - Sep 0, 2008

@ David I understand where you’re coming from and if you use subversion correctly there should never be a need to remove the hidden svn files. However, from time to time, I do find that it’s necessary - generally when someone has mistakenly duplicated directories using the Finder in OSX.


Bob - Jul 5, 2009

With the slightest of tweaks, this was actually useful to me. Sometimes svn crashes and leaves your working copy ‘locked’. Changing the cmd-line to: find -type f -name “lock” -exec rm ‘{}’ \; -print …enabled me to quickly get rid of all those pesky lock files. Just make sure there’s no real content called “lock” ;)


Mahbub - May 2, 2010

How about

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

It works for me :)