On Tue, Jan 03, 2017 at 12:15:02AM -0500, Ted Unangst wrote: > This option is not posix (not like that's stopped find accumulating a dozen > extensions), but it is in gnu and freebsd (for 20 years). it's also somewhat > popular among sysadmins and blogs, etc. and perhaps most importantly, it > nicely solves one of the more troublesome caveats of find (which the man page > actually covers twice because it's so common and easy to screw up). So I think > it makes a good addition. > > Code snatched from freebsd. > > In passing, I'll also note that the man page example is very inefficient. > $ find . \( -name \*.jpg -o -name \*.gif \) -exec rm {} \; > This would be much faster with +. We can fix that too, but I'll add that a lot > of the online advice suggests -delete, and if not available, -exec rm {} \;, > instead of the smarter + exec. Not surprising since even the man page gets > this wrong. >
no opinion on the addition, but if there is a better way to write the examples that are there, i think you should take the time to do so. i'd also slightly prefer we show the more traditional way to do it, though i appreciate that might not make a ton of sense for find(1). some comments on the man parts: > Index: find.1 > =================================================================== > RCS file: /cvs/src/usr.bin/find/find.1,v > retrieving revision 1.91 > diff -u -p -r1.91 find.1 > --- find.1 11 Sep 2015 18:58:16 -0000 1.91 > +++ find.1 3 Jan 2017 05:04:52 -0000 > @@ -182,6 +182,23 @@ was started, rounded up to the next full > .Ar n > 24-hour periods. > .Pp > +.It Ic -delete > +Delete found files and/or directories. i think "and" is sufficiently clear. > +Always returns true. > +This executes > +from the current working directory as > +.Nm > +recurses down the tree. > +It will not attempt to delete a filename with a > +.Dq Pa / > +character in its pathname relative to > +.Dq Pa \&. i'd use Sq rather than Dq for single letters if you really need it quoted. and check, but i think you need \& after the dot, not before, or you'll get a double space injected. jmc > +for security reasons. > +Depth-first traversal processing is implied by this option. > +The > +.Ic -delete > +primary will fail to delete a directory if it is not empty. > +Following symlinks is incompatible with this option. > .It Ic -depth > This primary always evaluates to true. > The same as specifying the > @@ -587,6 +604,7 @@ primaries > .Ic -anewer , > .Ic -cmin , > .Ic -cnewer , > +.Ic -delete , > .Ic -empty , > .Ic -execdir , > .Ic -flags ,