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.

yw5643
  • 151

1 Answers1

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.)

Stephen Kitt
  • 434,908