Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Recursively remove all .svn directories (See related posts)

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


Update: Thankyou iburrell

Comments on this post

iburrell posts on Aug 08, 2005 at 02:33
That isn't the best way to do it. It will break if you have lots of .svn directories. Then the command line will be too long and you will get 'argument list too long'. Recent bash have enormous buffers so this is less of a problem. xargs solves this problem.

The other problem is any file with spaces in the name will cause bash to treat it as two arguments. Which could give an error or could delete the wrong file. find -print0 and xargs -0 solve this problem.

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


The other way is to do:

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

nocans posts on May 31, 2008 at 22:57
find . -name .svn -exec 'rm -rf {}\;'

Doesn't work on solaris. Use this for all unixes:

rm -rf `find . -name .svn`
johnfyoung posts on Mar 04, 2009 at 19:38
On Mac OS 10.5, I used:
find . -name .svn -exec rm -rf {} \;

Note the space between the braces and the backslash.
Marcossp posts on Aug 18, 2009 at 01:56
We use find command to find all .svn folders beginning from current directory.

$ find . -type d -name .svn
./.svn
./sourceA/.svn
./sourceB/.svn
./sourceB/module/.svn
./sourceC/.svn

It is possible to pass these directories directly to rm command, using grave accent quotes (key to left of '1')

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

So, this will remove every .svn folder beginning from current directory.
source code: bash script (as my site

#!/bin/sh
echo "recursively removing .svn folders from"
pwd
rm -rf `find . -type d -name .svn`

You may save this script to /usr/bin/csvn (or other binary folder included in path) and use later to get 'clean' project source without typing lengthy commands.

For example,

$ svn checkout svn://server.com/svn/project
A project/index.php
A project/sourceA/a.php
A project/sourceA/a1.php
A project/sourceA/a2.php
A project/sourceB/b.php
A project/sourceB/module/lib.php
A project/sourceC/c.php
Checked out revision 15.
$ cd project
$ csvn
recursively removing .svn folders from
/Users/anyexample/Source/project
markalosey posts on Sep 12, 2009 at 17:23
If you just want a clean checkout without any .svn directories, it's a lot less work to just svn export /path/to/checkout

mozart_ar posts on Feb 27, 2010 at 19:26
Removing all, except svn

find . \! \( -path *svn* \) -type f -exec rm {} \;

You need to create an account or log in to post comments to this site.


Related Posts