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.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
yw5643
  • 131
  • 1
  • 4
  • 12
  • 1
    See [find: prune does not ignore specified path](http://unix.stackexchange.com/questions/109900/find-prune-does-not-ignore-specified-path) – steeldriver Aug 31 '16 at 12:10

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
  • 411,918
  • 54
  • 1,065
  • 1,164