Skip to content
Tags

find + rm = disaster

by admin on November 12th, 2007

Some time ago I wanted to to detach a working copy of some code I have been working on for several years so I could import it into a new repository on a different server.  I did something similar to this:

find -name ".svn" . | xargs rm -rf

Which did *almost* what I wanted.  The problem is that if any of the paths that are returned by find have a space in them, rm tosses everything up to the space.

In other words, if you have something like this:
/Documents/Projects/My Really Important Stuff/Project1

and My Really Important Stuff contains more than just Project1, you can kiss it all goodbye.

So, today I needed to do something similar, but I did it this way instead, which is MUCH safer:
find . -name ".svn" | while read f; do rm -r "$f" ; done

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS

Spam protection by WP Captcha-Free