On Mon, Jan 31, 2022 at 9:08 PM admin4 <[email protected]> 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) >
In theory, we could do this: $ find . -delete -name "*f25020672.avi*" find: warning: the test `-name "*f25020672.avi*"` does nothing because no action depends on it. ... but all those files would still have been deleted. However, the documentation very deliberately and clearly points out this risk: Warnings: Don't forget that the find command line is evaluated as an expression, so putting -delete first will make find try to delete everything below the starting points you specified. When testing a find command line that you later intend to use with -delete, you should explicitly specify -depth in order to avoid later surprises. Because -delete implies -depth, you cannot usefully use -prune and -delete together. Beyond clearly documenting how to use the tool (which I think we do) I'm not sure what to do about the risk that admin4 is pointing out. Well, other than making the user pass a quiz on how to use it the first time they invoke it, which isn't at all in the spirit of Unix and would be hard to do in a POSIX-compliant way that wasn't deeply user-surprising.
