Acerbic Resonance

There’s no substitute for a good subtitle.

find + rm = disaster

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


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *