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

Daniel Morrison draker at gmail.com
Fri May 9 22:45:02 ADT 2008


2008/5/9 Luke Gavel <fidomail2002 at yahoo.ca>:
> I suppose, if CPU cycles were 'expensive', -n might shave off some extra cycles rather than piping it to the grep's exit code.  Other than that, I don't see any real difference, if there really is one.  There likely isn't any difference because you're still having to pass it to the bash 'test' system:

Well now, talking about performance, it's the fork & exec in order to
start grep which is expensive, versus the [ bash built-in test.  But
there's only one anyway, and in any case the vast amount of time is spent
reading the disk.  The reason your first test took longer than the rest is
that the subsequent ones benefitted from caching.

I like mine better because I only have one place to change the name of the
file being searched for, rather than two.

Alternatively, I'd rather use locate (assuming that updatedb is run
regularly and to-the-minute accuracy is not required).  But locate has
return codes like find -- there is only a non-zero return if locate
encounters an operational error.

-D.

> [lgavel at d114-001 local]$ time [ -n "`find / -name traceroute -print 2> /dev/null`" ] && echo "Found it" || echo "it ain't there, Dave"
>
> real    1m48.493s
> user    0m0.443s
> sys     0m1.997s
> Found it
> [lgavel at d114-001 local]$ time [ -n "`find / -name traceroute -print 2> /dev/null`" ] && echo "Found it" || echo "it ain't there, Dave"
>
> real    1m18.710s
> user    0m0.406s
> sys     0m1.801s
> Found it
> [lgavel at d114-001 local]$ time find / -name traceroute -print 2> /dev/null | grep "traceroute" &> /dev/null && echo "Found it" || echo "it ain't there, Dave"
>
> real    1m19.495s
> user    0m0.464s
> sys     0m1.772s
> Found it
> [lgavel at d114-001 local]$ time find / -name traceroute -print 2> /dev/null | grep "traceroute" &> /dev/null && echo "Found it" || echo "it ain't there, Dave"
>
> real    1m33.082s
> user    0m0.419s
> sys     0m1.959s
> Found it



More information about the nSLUG mailing list