Sam Wilson

Wikimedia user link badge Mastodon user link badge GitHub user link badge

Pruning find

Fremantle

I don't know why I always forget how to exclude things from find results.

This answer by Laurence Gonsalves on Stack Overflow has made me realise I was thinking about it wrongly: "it's an action (like -print), not a test (like -name). It alters the "to-do" list, but always returns true."

I'm searching for a file in a MediaWiki images/ directory, but don't want to see the matching images under thumb/. This seems to do it:

find . -name 'thumb' -prune -o -name '*lorem*'

The -o is or, and the part after it is not evaluated if the part before is true.