Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

what command can I type into Terminal so that I can:

  • delete all .svn folders within a folder (and from all subdirectories)
  • but not delete anything else

?

share|improve this question

1 Answer 1

up vote 55 down vote accepted
cd to/dir/where/you/want/to/start
find . -type d -name '.svn' -print -exec rm -rf {} \;
  • Use find, which does recursion
  • in the current directory .
  • filetype is directory
  • filename is .svn
  • print what matched up to this point (the .svn dirs)
  • exec the command rm -rf (thing found from find). the {} is a placeholder for the entity found
  • the ; tells find that the command for exec is done. Since the shell also has an idea of what ; is, you need to escape it with \ so that the shell ignores it, and just passes to find
share|improve this answer
1  
Good solution. While find has -delete it won't delete non-empty directories. This approach is cleaner than e.g. starting to match parts of the whole path of files. –  Daniel Beck Feb 9 '12 at 17:02
    
great, perfect... it worked! thanks –  Mikey Feb 9 '12 at 17:02
7  
I'd recommend running it without the -exec rm -rf {} \; the first time to make sure it's only finding what you want it to. I've never had an issue where I've accidentally deleting the wrong thing with it, because I always check first. –  Rob Feb 9 '12 at 18:09
2  
@Rob good point, i usually do -exec echo rm -rf {} \; then remove the echo. –  Rich Homolka Feb 9 '12 at 18:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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