Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I run this command on a Unix box:

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

I wanted to delete any file called CVS within any directory from the current directory and it deleted everything.

Fortunately all I had to do to recover was check out again from CVS. Imagine if I specified / as the starting directory!

I think the reason is that 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?

share|improve this question
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
@Gilles Can you please explain the command you've proposed? Thank you. – Eugene S Jun 28 '12 at 17:17
@Eugene, the difference is the echo part, which just prints the command that would otherwise have been executed. The elipsis are just Gilles' way to not repeat the other parameters in the example. So, the full version would be find . name CVS -exec echo rm -fr {} \; – Arjan Jun 28 '12 at 17:29
@Arjan Thank you for your comment. I believe than under ellipsis you mean the underline "_", right? – Eugene S Jun 28 '12 at 17:31
Yes, @Eugene, these are actually three little dots! – Arjan Jun 28 '12 at 17:32
up vote 7 down vote accepted

You're missing the dash before -name, hence it was looking for paths named ., name and CVS, where the dot references the current folder, hence deleting all.

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

You can easily test by using echo before the command you want to run:

find . name CVS -exec echo rm -fr {} \;
share|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
Paths named name CVS and obviously ., which it found. – Rob Jun 28 '12 at 17:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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