How to find only files, with which command xyz ends successfully

find

I'm trying to find all files, that make a given command end successfully (exit code 0).

The find man page says about -exec: Execute command; true if 0 status is returned.

Although listed under Actions, I thought, that this means, that files that make the given command end with 0 will be displayed.

Past uses and trying with find . -exec true \; and find . -exec false \;, which both gave no output, prove me wrong, though.

A sample invocation would be find . -exec ./is_dir.py {} \;, which should print all found directories. (I know, that you can test for this particular case. I couldn't find a combination of tests, that satisfy my actual needs.)

Failing to formulate my problem good enough, searching yielded no results.

Best Answer

You can do:

find . -exec ./is_dir.py {} \; -o -print

It will list everything that is not a directory. Assuming that is_dir.py is executable (chmod +x is_dir.py) and contains something like:

#!/usr/bin/env python

import sys
import os

if os.path.isdir(sys.argv[1]):
    sys.exit(0)
sys.exit(1)

And if is_dir.py generates output of its own, you can do:

 rm -f nondir.lst
 find . -exec ./is_dir.py {} \; -o -exec echo  {} >> nondir.lst \;

so that its outoput doesn't get mixed with the list of names for which is_dir.py fails.