Recursively Delete Subversion (.svn) Directories

I alway am hunting for this little command-line gem, so I figured I’d post it and share the quick shell script I added to my home directory to make it faster for me to do this.

Often, I will find an old project (or inherit, or destroy) a project with subversion directories and files in it. However I get there, every few months I find myself wanting to remove subversion folders recursively and am not well-versed in shell scripting to remember how to do it.

Here’s the single line magic removal of .svn directories:

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

And here’s the script I wrote and placed in my home directory, ~/recursively-kill-svn.sh:

while true; do
	read -p "Do you want to recursively delete all .svn folders/files in the current directory (`pwd`)? (y/n)" yn
	case $yn in

		[Yy]* ) rm -rf `find . -type d -name .svn`; echo ".svn directories in `pwd` have been recursively killed!!1"; break;;

		[Nn]* ) echo "I've done absolutely nothing."; exit;;
		* ) exit;
	esac
done

With this in my home directory, I just move to a project folder, type:

~/recursively-kill-svn.sh

…and hit enter. Enjoy.

P.S. If it’s not working for you (or auto-completing when you hit tab in Terminal) make sure it has permissions to execute:

chmod +x ~/recursively-kill-svn.sh

P.P.S. You can rename the file to whatever you like.

2 Comments

  1. Greg Larkin says…

    Depending on the number of .svn directories in the hierarchy, it’s possible that you’ll exceed the command-line length with the results of your backticked find command. If that happens, give this command a try:

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

    The combination of -print0 and -0 enables deletion of paths with embedded space in the name.

    Hope it helps,
    Greg

  2. andy says…

    Awesome, thanks Greg!

RSS feed for comments on this post. TrackBack URL

Leave a Comment

October 5, 2011

Filed in Development, Miscellaneous, Terminal, Tools

There are 2 comments »


« Back to the Blog