Re: [bug #61774] Docs for find -delete out of sync

Bernhard Voelker <[email protected]>
Newsgroups gmane.comp.gnu.findutils.bugs
Message-ID <[email protected]>
On 1/31/22 19:34, admin4 wrote:
> # DANGER! THIS DELETES ALL (!!!) FILES IN THE CURRENT DIRECTORY! (NOT ONLY THE -name “*FILES*” SPECIFIED )
> find . -delete -name "*f25020672.avi*" <- why does it do that? it is like it completely ignores anything after -delete X-D (and just deletes everything in the current dir)

It is pretty clear what happens here:

find(1) was asked to
- start a search in the current directory ".",
- and to delete all files and directories (implicitly using -depth),
- and then to apply the filter for -name '*.avi'.
As the whole command line has already an action (-delete), find does not
implicitly add the default action (-print), and therefore nothing happens
after -name.

I don't think anything surprising is going on here, and find exactly does what
is being asked to do: it processes the command line from left to right.

> # this would have been the correct way to do it
> find . -name "*f25020672.avi*" -delete

Sure, because that first filters for the name, and then performs the deletion
on the remaining files matching that criteria.

And this is what I've tried to emphasize by moving the warning in bold right
after the first sentence about -delete:

  *Warning*: Don't forget that find evaluates the command line as an expression,
  so putting -delete first will make find try to delete everything below the
  starting points you specified.

Have a nice day,
Berny
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.