On 9/7/07, Eric Blake <[EMAIL PROTECTED]> wrote: > > Maybe something can be added under "Expressions" explaining exactly how > find > > interprets expressions. > > Where do you propose adding it? There is already information there - for > each file name being visited, find evaluates the expression from left to > right until it hits something that evaluates to false. -delete evaluates > to true if it successfully deletes anything, so by listing it first, you > are asking find to delete a file, and if it fails, then do the next part > of the expression (which finally does name filtering). Usually, you want > to do the filtering first (for example, -iname returns false if the file > name does not match the pattern), then only -delete what is left. Maybe > what we should add is a sentence to -delete: > > Note that -delete is usually placed at the end of an expression, after all > earlier tests have filtered the list of which files to delete.
Yes. If I would've seen that hint I would have thought twice about find's syntax before running the delete. I realize now that I didn't read the sentence in the manual about expression parsing because it was under "description", not under "expressions" (where I expected it). I don't blame the manpage for not conforming to my expectations. But perhaps some hints in the later sections will prevent future mistakes like mine. > ps. Why is "find -iname *-1*.jpg" invalid? I didn't explicitly indicate > the > > path to search so find assumes the working directory. > > Because you did not protect it from filename expansion by the shell. If > your current directory happens to have a single file that matches that > pattern, then you are really invoking "find -iname myfile-1.jpg", which > does not find everything based on the pattern. And if your current > directory happens to have two or more files that match the pattern, you > have just given find a syntax error, since in "find -iname f1-1.jpg > f2-1.jpg", f2-1.jpg falls in the position of an expected expression, but > does not match any known expression. You probably meant: > > find -iname "*-1*.jpg" Ah, thanks. I didn't know a shell would do expansion there. Matthijs
