The basic idea is simple: Do a recursive traveral of the files hierachy starting with a directory. Whenever a file or directory is visited, perform a specified action on the node you are visiting. The action is specified with a boolean expression.
The problem is doing this from a shell command. These boolean expressions will be ugly.