4
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
?
3This 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 'SO- stop being evil' – 2010-10-30T13:38:23.343@Gilles Can you please explain the command you've proposed? Thank you. – Eugene S – 2012-06-28T17:17:02.440
2@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 befind . name CVS -exec echo rm -fr {} \;
– Arjan – 2012-06-28T17:29:13.030@Arjan Thank you for your comment. I believe than under ellipsis you mean the underline "_", right? – Eugene S – 2012-06-28T17:31:47.150
1
Yes, @Eugene, these are actually three little dots!
– Arjan – 2012-06-28T17:32:33.540