tags:

views:

301

answers:

4

I'm trying to remove all the .svn directories from a working directory.

I thought I would just use find and rm like this:

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

But the result is:

find: rm -rf ./src/.svn: No such file or directory

Obviously the file exists, or find wouldn't find it... What am I missing?

+11  A: 

You shouldn't put the rm -rf {} in single quotes.

As you've quoted it the shell is treating all of the arguments to -exec it as a command rather than a command plus arguments, so it's looking for a file called "rm -rf ./src/.svn" and not finding it.

Try:

find . -iname .svn -exec rm -rf {} \;
Dave Webb
Yep. You're both right. I realized that, too.
Sam Hoice
I think that the last time I used -exec it was for a grep which I needed to quote the regex, and so I had that in my head. Thanks all!
Sam Hoice
I said "Don't need" because it looked like Sam thought he needed to. However, I see that this is ambiguous and will edit.
Dave Webb
+1  A: 

You can also use the svn command as follows:

svn export <url-to-repo> <dest-path>

Look here for more info.

Darryl Hein
Awesome. I figured I could do that but I didn't know how to export the working directory. Thanks!
Sam Hoice
+1  A: 

Try

find . -iname .svn -exec rm -rf {} \;

and that probably ought to work IIRC.

Eric Wendelin
+5  A: 

Just by-the-bye, you should probably get out of the habit of using -exec for things that can be done to multiple files at once. For instance, I would write that out of habit as

find . -iname .svn -print | xargs rm -rf

or, since I'm now using a Macintosh and more likely to encounter file or directory names with spaces in them

find . -iname .svn -print0 | xargs -0 rm -rf

"xargs" makes sure that "rm" is invoked only once every "N" files, where "N" is usually 20. That's not a huge win in this case, because rm is small, but if the program you wanted to execute on every file was large or did a lot of processing on start up, it could make things a lot faster.

Paul Tomblin
Awesome. I'll check out the man page for xargs, and for the record, I'm on a mac, too. w00t!
Sam Hoice
Alternatively, you can end the -exec clause of find with "\+" instead of "\;", which is equivalent to using -print0 and piping to xargs.
Adam Rosenfield
@Adam, that must be fairly new? Mind you, I switched to using args back in the days of Ultrix on MicroVax, so "new" might mean "in the last 15-20 years".
Paul Tomblin