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?
Asked
Active
Viewed 1,137 times
1 Answers
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
-
8Equivalently, using `-o` (or): `find . -exec yourscript {} \; -o -print`. – John Kugelman Apr 08 '19 at 19:07