0

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.

Thanks

  • 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 07 '09 at 11:50

5 Answers5

3

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 {} \;
Dan Carley
  • 25,617
  • 5
  • 53
  • 70
  • the OP asked for **"files of a specific extension"**, not (only) directories. – PEra Oct 07 '09 at 10:26
  • 2
    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 07 '09 at 10:35
  • 2
    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 07 '09 at 13:13
  • `-delete` doesn't play well with directories. Good call on `-depth`. – Dan Carley Oct 07 '09 at 14:56
2

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!

mat_jack1
  • 399
  • 1
  • 3
  • 8
  • 2
    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 07 '09 at 13:16
0

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 {} \;
Ali Mezgani
  • 3,850
  • 2
  • 24
  • 36
0

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)

Matthieu
  • 106
  • 2
  • This doesn't work recursively. Presumably the www directory has other directories which also contain a .svn directory. – Kamil Kisiel Oct 08 '09 at 16:26
-1

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.

PEra
  • 2,875
  • 18
  • 14
  • this would remove also foo.svn, which is not the wanted behavior – drAlberT Oct 07 '09 at 10:18
  • 1
    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 07 '09 at 10:25