How to tell if the output of the "find" command is empty?

Here's my version. :)

[ -z "$(find /this/is/a/path/ -name 'core.*')" ] && true

Edited for brevity:

[ -z "$(find /this/is/a/path/ -name 'core.*')" ]

When you say you want it to return a particular number, are you referring to the exit status? If so:

[[ -z `find /this/is/a/path/ -name core.*` ]]

And since you only care about a yes/no response, you may want to change your find to this:

[[ -z `find /this/is/a/path/ -name core.* -print -quit` ]]

which will stop after the first core file found. Without that, if the root directory is large, the find could take a while.

Tags:

Bash

Pipe