Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a dir:

$ tree
.
|-- CVS
|   |-- Entries
|   |-- Entries.Log
|   |-- Repository
|   `-- Root
|-- dirA
|   |-- CVS
|   |   |-- Entries
|   |   |-- Repository
|   |   `-- Root
|   |-- file1
|   `-- file2
|-- dirB
|   |-- CVS
|   |   |-- Entries
|   |   |-- Repository
|   |   `-- Root
|   |-- file3
|   `-- file4
|-- file5
`-- file6

I can find all files I want to delete with this command:

$ find . -name CVS -prune -o -type f -print

But if I change -print to -delete

$ find . -name CVS -prune -o -type f -delete

Everything is gone. Why?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Look at the man pages for find, under -delete:

When testing a find command line that you later intend to use with -delete, you should explicitly specify -depth in order to avoid later surprises. Because -delete implies -depth, you cannot usefully use -prune and -delete together.

You can most probably just use -exec rm {} + instead of -delete in this context to do what you want, but as always when playing with fire: make very sure that it works before going in hard.

share|improve this answer

Your Answer

 
discard

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.