Recursively remove .svn directories

NOTE: Check the comments for variable solutions for this predicament. Thanks to everyone for participating!

Sometimes you find yourself in situations where svn cleanup just doesn’t cut it — you need to remove the .svn files and re-add everything. It’s a pain to do that file by file so here’s a little method for doing it all at once.

[bryan@crainbandy] rm -rf `find . -type d -name .svn`

UPDATE (via comments, thanks meinholz) alternatively you can do:

[bryan@crainbandy] find . -type d -name .svn -exec rm -rf {} \;

Don’t say I didn’t tell you.
Bryan

Related reading

10 Responses to “Recursively remove .svn directories”

  1. Kalpesh Sutaria  on May 20th, 2009

    Why wouldn’t you use ’svn export’ instead?

  2. meinholz  on May 21st, 2009

    Another option is:

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

    Tye -type d isn’t really necessary. If you name a file .svn, doom on you.

    I don’t know if this way is better or not, just an alternative.

  3. bryan  on May 21st, 2009

    Ah yeah. I’m going to append that to the post — thanks!

  4. lbruno  on May 21st, 2009

    find . -name .svn | xargs rm -rf

    -exec is for: -exec mv {} /other/ \;

  5. Tom  on May 21st, 2009

    I’d actually say that this:

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

    is better if for no other reason than the lack of catastrophe in the event of a typo. Sure, it’s being fearful, but that’s definitely better than deleting the whole tree accidentally.

  6. levi_h  on May 22nd, 2009

    Or the xargs variant of course:

    find . -name .svn | xargs rm -r

    I’m impressed with anyone who can remember the syntax for find’s exec switch :)

  7. Chris  on May 23rd, 2009

    You should use “-depth” as well for the find command.

    The reasoning is that without it it will delete the top directories first and then try to delete the already deleted sub directories which wont work for obvious reasons.

    Makes no difference if you run a one liner in a shell but might be a PITA if run inside a script.

  8. bryan  on May 23rd, 2009

    Thanks for all the comments guys, I will be updating the post shortly.

  9. Ryan  on September 28th, 2009

    Another way:

    svn export working_directory new_directory

    It will copy a directory to the new location without .svn directories.


Leave a Reply