Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Quick question, how do I recursively remove files of a specific extension? I wish to remove all .svn folders from a project.

rm -Rf www/ "*.svn"

The above seems to remove everything. Im using FreeBSD.


share|improve this question
You write "remove files of a specific extension", but that's not what you want to do. What you want to do (and what most of the answers have been about) is how to remove all directories named exactly ".svn" and their contents. So please clarify your question. – Teddy Oct 7 '09 at 11:50

Ensure that you are happy with the list first.

find www -name '.svn' -type d -ls

Restrict to directories. SVN always names them .svn.

find www -depth -name '.svn' -type d -exec rm -rf {} \;
share|improve this answer
the OP asked for "files of a specific extension", not (only) directories. – PEra Oct 7 '09 at 10:26
I think the OP might be confused. They also said "I wish to remove all .svn folders from a project". Given that scope I think that anything like -iname '*.svn' is asking for trouble. – Dan Carley Oct 7 '09 at 10:35
You can add -depth at the start of the command line and you won't get the errors. You might also be able to use -delete rather than -exec, but I don't know how it will behave with directories. – David Pashley Oct 7 '09 at 13:13
-delete doesn't play well with directories. Good call on -depth. – Dan Carley Oct 7 '09 at 14:56

I like to use the xargs command, i find it more intuitive, so:

find www -name '.svn' -type d -print0 | xargs -0 rm -r

if you want to remove .svn folders, if you are interested in deleting files:

find www -name '.svn' -type f -print0 | xargs -0 rm

or you can remove everything:

find www -name '.svn' -print0 | xargs -0 rm -r

if you want to be sure of what you will delete, launch the find command without the xargs :-)

good luck!

share|improve this answer
You really want to use find .... -print0 | xargs -0 ... if you're going to do this, otherwise spaces may cause you problems. – David Pashley Oct 7 '09 at 13:16
that's true, i never realized that, thanks! – mat_jack1 Oct 8 '09 at 9:35

chdir to the the working directory and run:

find . -iname '.svn' -exec rm -fr {} \;
OR you can specify the path directory like this:

find path -iname '.svn' -exec rm -fr {} \;

share|improve this answer
the OP asked for "files of a specific extension", not (only) directories. – PEra Oct 7 '09 at 10:26

By typing :

rm -Rf www/ "*.svn"

You ask to remove the www folder and every *.svn files.

What you certainly want is to remove every *.svn inside the www folder, so you should use:

rm -Rf www/*.svn

(without the space)

share|improve this answer
This doesn't work recursively. Presumably the www directory has other directories which also contain a .svn directory. – Kamil Kisiel Oct 8 '09 at 16:26

not sure if this is the best way to get rid of a repository, but this should do what you need:

find www -name "*.svn" -exec rm -rfv {} \;

Update: here is a nice description of BSD's find.

share|improve this answer
this would remove also foo.svn, which is not the wanted behavior – drAlberT Oct 7 '09 at 10:18
Sure, it was exactly what the OP asked for: "how do I recursively remove files of a specific extension?". So please remove the down-vote... – PEra Oct 7 '09 at 10:25

Your Answer


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