Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I issue the following command to find the .svn directories:

find . -name ".svn"

That gives me the following results:


How could I process all these lines with rm -fr in order to delete the directories and their content?

share|improve this question
GNU find has the -delete option. –  Marco Sep 9 '13 at 8:49
Or you can add -exec rm -r "{}" \; to the end of the find - be careful when using rm -r! :) –  Drav Sloan Sep 9 '13 at 8:52
@Marco The delete option does not seem to work on directories. –  Super Chafouin Sep 9 '13 at 9:01
@Drav It works, thanks ! Maybe you could add this as an answer so I would accept it ? –  Super Chafouin Sep 9 '13 at 9:07
@SuperChafouin but will not work for paths with spaces in them (hence using -exec with quoted "{}"). –  Drav Sloan Sep 9 '13 at 9:55

4 Answers 4

up vote 11 down vote accepted

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
share|improve this answer
I have seen advice to always run -type after -name in find commands, since calls to stat to get the type are expensive. I just tried it myself on a fairly large bunch of files, and it seems to be true: running find . -name 'foo' -type d took 19 secs, while find . -type d -name 'foo' took 32 secs. So about 50% longer time to run -type first. –  spinup Mar 16 at 16:37

Here is a portable way to do it, i.e. here something that doesn't require GNU find.

Especially if you have a lot of .svn directories, using a + instead of a semicolon as find command terminator is is slightly more optimized:

find . -type d -name ".svn" -exec rm -rf {} +

Note also that you never need to quote the curly braces when used that way.

share|improve this answer

Assume you are using gnu find, you can use the -delete option:

find . -name test -delete

which is easier to remember.

share|improve this answer
Consider expanding your post with an explanation of the command (or documentation to back up your solution). Often one (or two) line answers are not the most illuminating. –  HalosGhost Aug 10 '14 at 23:02
This doesn't work on non-empty directories. –  belacqua Dec 16 '14 at 20:47

Bash specific solution:

shopt -s globstar
rm -r **/.svn
shopt -u globstar #optional. this will disable globstar expansion
share|improve this answer
Note for command line expansion of globs that match many files, there is a limit to the number of files you can match with this mechanism. Going over this limit will result in bash: /bin/rm: Argument list too long –  Drav Sloan Sep 9 '13 at 10:06
@DravSloan is correct, but that limit is in the hundreds of thousands of files. It's something to bear in mind, but probably won't be a problem for most people. –  evilsoup Sep 9 '13 at 10:26

Your Answer


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.