2

I have a folder that has a .SVN solution in it.

I want to go throught the entire directory and its subdirectories, and delete the .svn folder.

I have bash installed, so I can use grep if need.

7
find <path> -type d -name '.svn' -exec rm -rf {} \+

Finds all directories of name '.svn' and deletes them recursively.

I'd be really cautious of doing this if you don't own the checkout directory and don't understand why these directories are present. Also note roe's answer about svn export.

  • that should probably be -name and \; right? – falstro Dec 9 '09 at 16:02
  • Yeah, -nane was a typo :) The \+ tells -exec to call the command a bit more conservatively by appending arguments. – Dan Carley Dec 9 '09 at 16:04
  • sweet! I always used xargs for that, does it also terminate the command, or do I need to add a \; as well if I want more predicates? – falstro Dec 9 '09 at 18:22
6

in bash:

removesvn() {
  cd $1
  for f in */.svn; do
    [ -d "$f" ] && removesvn ${f%/.svn}
  done
  [ -d "$f" ] && rm -rf .svn
}

removesvn .

should navigate down through all folders containing an .svn folder and remove it.

HOWEVER, you're probably better off using svn to export (svn export I beleive) a vanilla tree without versioning information, which is probably what you're looking for.

EDIT
Note that the bash script above only removes .svn folders which are connected to the original one (i.e. it won't remove a/b/c/.svn if b doesn't contain a .svn). If you just want to clear out .svn stuff in your filesystem, find will probably do a better job.

4

You can combine find and rm with xargs to find and remove all .svn subdirectories from a root directory.

First test the find command to check if it finds the right subdirectories,

find . -name ".svn"

This should display a list of all .svn subdirectories in the current working directory (.). Make sure that these are indeed the directories that you want to remove. Then run the following command to actually remove them (note: this cannot be undone),

find . -name ".svn" | xargs rm -vrf

See man rm and man find for an explanation of the options.

1

I used this technique:

find [path] -name .svn -print0 | xargs -0 rm -R

It worked just fine for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.