26

I would like to recursively find all the files for which a script which accepts a file as an argument returns a non-zero value. Any idea how to do this using 'find' or a similar tool?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
mitanyen
  • 363
  • 2
  • 4

1 Answers1

38

find’s -exec action can be used for this:

find . \! -exec yourscript {} \; -print

will print the names of all files for which yourscript fails.

-exec can be used in this way to turn appropriate external commands into find tests.

You can limit the files which are tested by adding find tests before -exec; for example, to limit the candidates to regular files, add -type f:

find . -type f \! -exec yourscript {} \; -print
Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164