7

How do I recursively delete all .svn directories, starting with the directory I am in?

djsmiley2kStaysInside
  • 6,643
  • 2
  • 31
  • 43
  • 1
    What platform -- Windows? Linux/UNIX? Something else? – Chris J Jun 01 '11 at 15:36
  • possible duplicate of [Command to recursively remove all .svn directories on Windows](http://stackoverflow.com/questions/4889619/command-to-recursively-remove-all-svn-directories-on-windows) – Chris J Jun 01 '11 at 15:37
  • It's on Linux, Debian –  Jun 01 '11 at 15:38
  • Funny enough, I needed this in the morning when committing something to a mercurial repository. I ended up adding everything and removing the .svn folders before committing instead. And now you come up with this question, apparently Ned's solution is what I needed... – Tamara Wijsman Jun 01 '11 at 18:49

3 Answers3

12

Keep in mind that svn provides the "export" command that provides you with a copy of your working tree, but without all the .svn directories sprinkled in. This could be what you want.

$ svn export /tmp/copy_of_my_tree
Ned Batchelder
  • 1,296
  • 1
  • 11
  • 15
  • this won't work for a repo, you have no access to (e.g. zipped and mailed to you) – mbx Aug 08 '11 at 15:24
9

If you're working in Linux (or equivalent), you can just do the following:

find . -name .svn -exec rm -rf {} \;
Oliver Charlesworth
  • 1,052
  • 7
  • 11
  • 2
    Or, better, and as Piskvor mentions, use `-type d` to ensure that one isn't accidentally deleting something that isn't a directory. – JdeBP Jun 01 '11 at 21:10
7

In any modern UN*X-like system (Linux, Mac OS X, FreeBSD):

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

find:

  • in the current directory
  • directories
  • with name .svn
  • and when found, run rm -rf on each
  • 4
    That's almost the canonical idiom. You forgot `xargs` to reduce the number of `rm` processes needed: `find . -type d -name '.svn' -print0 | xargs -0 rm -rf --` – JdeBP Jun 01 '11 at 21:12
  • To add to @JdeBP's comment: Some `find` implementations also support `-exec rm -rf {} +` or even `-delete` to achieve the same thing. – u1686_grawity Jun 02 '11 at 11:06