Skip to main content
4 of 5
recommended to keep -type calls after -name for efficiency: explanation in comment

Find can execute arguments with the -exec option for each match it finds. It is a recommended mechanism because you can handle paths with spaces/newlines and other characters in them correctly. You will have to delete the contents of the directory before you can remove the directory itself, so use -r with the rm command to achieve this.

For your example you can issue:

find . -name ".svn" -exec rm -r "{}" \;

You can also tell find to just find directories named .svn by adding a -type d check:

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

Warning Use rm -r with caution it deletes the folder and all its contents.

If you want to delete just empty directories, a way to hack around that is to use rmdir instead of rm -r:

find . -name ".svn" -type d -exec rmdir "{}" \;

This will delete empty directories and give errors for directories with contents. If you do not want to see the errors, redirect the STDERR to /dev/null

find . -name ".svn" -type d -exec rmdir "{}" \;  2> /dev/null
Drav Sloan
  • 14.7k
  • 4
  • 49
  • 45