Do not use GNU find when recursion is not needed

Published: Wednesday, Nov 11, 2009 Last modified: Monday, Dec 9, 2024

Consider:

find . -name author-signature.xml -o -name 'signature*.xml'

It correctly returns:

./author-signature.xml
./signature1.xml

Oh, but I don’t what the ‘./’ prefix. Lets add -printf "%P\n", quickly check and sign-off.

Then later you get a report an incredulous report that author signatures aren’t being checked. WTF?

The -printf only applies when the second -name is successful, not when the first is.

The solution? Add some fecking brackets:

find . \( -name author-signature.xml -o -name 'signature*.xml' \) -printf "%P\n"

This is ugly, compare with the way I should have been doing it in the first place:

for i in author-signature.xml signature*.xml; do echo $i; done

Morale of the story, do not use GNU find. It’s against the UNIX philosophy and it’s an abomination of a command to use.

Though do not use ls for finding stuff either.