I run this command on a Unix box

find . name CVS -exec rm -fr {} \;

What i wanted to do is delete any file called CVS within any directory from the current directory and it deleted everything.

Fortunately all i had to do to recover is check out again from CVS. imagine if i specified / as the starting directory!

Edit

I think the reason it did that is because i used "name" instead of "-name". I just rerun it as

find . -name CVS -exec rm -fr {} \;

And it seem to work fine. What exactly happens if name is used as opposed to -name?

link|improve this question

1  
This why you should always be extremely careful around commands that might overwrite or delete files. Here a handy way to test would be find … -exec echo rm -fr {} \;. – Gilles Oct 30 '10 at 13:38
feedback

1 Answer

up vote 6 down vote accepted

You're missing the dash before -name, hence it was looking for paths named name and CVS:

The find utility recursively descends the directory tree for each path listed.

You can easily test using

find . name CVS -exec echo rm -fr {} \;
link|improve this answer
Yes just noticed that :) Thanks. – ziggy Oct 30 '10 at 12:24
@ziggy, in case you missed my edit: so it was looking for paths named name and CVS. – Arjan Oct 30 '10 at 12:27
Yes that makes sense. I have to be very carefull with this command. Thanks – ziggy Oct 30 '10 at 12:33
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.