0

I am new bee for Linux. I have a question about the command find. When I search a file under a directory, I would like to skip a sub-directory named publish

find ./ -path ./publish -prune -o -iname rdesvc -type f -print

It works fine:

./release/apps/rdeSvc/server/linux/rdeSvc

But, if I remove the parameter -print:

find ./ -path ./publish -prune -o -iname rdesvc -type f

It will output the sub-directory name with the search result:

./publish
./release/apps/rdeSvc/server/linux/rdeSvc

I feel confusion. Why the sub-directory name publish is outputted if I removed the parameter -print?

My distribution is CentOS 6.6 64 bit.

marked as duplicate by Gilles find Aug 31 '16 at 22:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4

This is a combination of find's default action being -print and find's operator precedence.

find ./ -path ./publish -prune -o -iname rdesvc -type f -print

is interpreted as

find ./ \( -path ./publish -prune \) -o \( -iname rdesvc -type f -print \)

so ./publish is pruned, and anything matching rdesvc is printed.

But

find ./ -path ./publish -prune -o -iname rdesvc -type f

is interpreted as

find ./ \( \( -path ./publish -prune \) -o \( -iname rdesvc -type f \) \) -print

so ./publish is pruned and printed, and anything matching rdesvc is printed. (The -prune action evaluates to true.)

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