[nSLUG] /usr/bin/find 'found'/'not found' exit codes?

Daniel Morrison draker at gmail.com
Fri May 2 01:59:50 ADT 2008

2008/5/2 Luke Gavel <fidomail2002 at yahoo.ca>:
> Are there any plans to modify the 'find' code to return another exit
> code or change the current meaning of the exit code?


> Right now, the find command only exits with error code #1 if it detects
> a syntax error.


find /usr/bin -name find

The find command evaluates every filename found on the filesystem that
matches the pattern ("/usr/bin") against the criteria (-name find), and
exits with a 0 exit code if it succeeds in doing this.

If it fails, for example, because some subdirectory is not traversable, it
returns a >1 exit code.  In this case it cannot guarantee that the file
you searched for is _not_ there.

> You have to pipe it through grep to get a #0 'found' or
> #1 'not found' exit code.  Why can't the find command do that itself?

How about:

user$ [ -n "`find /usr/bin -name find -print`" ] && echo found find ||
echo didn\'t find find
found find

user$ [ -n "`find /usr/bin -name found -print`" ] && echo found found
|| echo didn\'t find found
didn't find found


More information about the nSLUG mailing list