Can I make `find` return non-0 when no matching files are found?
find /tmp -name something | grep .
The return status will be 0
when something is found, and non-zero otherwise.
EDIT: Changed from egrep '.*'
to the much simpler grep .
, since the result is the same.
Exit 0 is easy with find, exit >0 is harder because that usually only happens with an error. However we can make it happen:
if find -type f -exec false {} +
then
echo 'nothing found'
else
echo 'something found'
fi