On Thu, 2007-11-01 at 16:03 -0700, Michael G Schwern wrote:
> Oh that's right, in Unix nobody would ever possibly put a space in a filename
> (a hate for later).  So I need to separate things with a null byte, ok...
> 
>       $ find . -print0 -name '*.txt' | xargs -0 rm
> 
> Whoopsie, everything's deleted.  10 gigs of fine public educational video,
> gone.  Turns out putting -print0 first instead of last causes some sort of
> crazy find switch boolean madness to short circuit and everything becomes 
> true.
> 
> I'm sure there's some perfectly self-consistent, logical and yet still TOTALLY
> INSANE reason why this is so making find the well-dressed, but completely off

Yes, of course, this is how it's always worked.

Because you're not really giving options to find, but an expression,
just happens that most of the operators start with hyphen.

So the -print/-print0/-ls/-exec/whatever is evaluated at the point in
the expression where it appears. Too bad for you the first operator in
an expression is of course always executed by definition.

Sure, I can see why this is hateful and totally surprising to anyone new
to find, it is one of those tools where the the options/arguments are
non-standard and don't behave like other tools. Unlike dd, tar, ps, and
other tools where the non-standardness is totally gratuitous and very
crap, at least find is deviating for good reason.

One of the rules to save your bacon, just like you should always
'select ... from ... where ...' before you 'delete from ... where ...',
'find ... -print' before you 'find ... -exec rm \;' or xargs equivalent.

Cheers,

Martin. 

Reply via email to