find with -delete option on absolute paths

Chris H bsd-lists at bsdforge.com
Wed Mar 11 04:43:23 UTC 2015


On Tue, 10 Mar 2015 20:31:52 -0700 Matt Tagg <wamatt at gmail.com> wrote

> Hey BSD folks
> 
> I believe this was discussed previously (2013), though I could not
> find a resolution.
> 
> To recap, suppose we try deleting files on an absolute path:
> 
> matt at mtbook:/% find /tmp/foo/* -delete
> find: -delete: /tmp/foo/bar.txt: relative path potentially not safe
> 
> As you can see it gives an error and quits. However if we instead try this:
> 
> matt at mtbook:/% gfind /tmp/foo/* -delete
> 
> GNU Find throws no error and works as expected ('bar.txt is deleted')
> 
> So as an end user, I find this rather confusing. How can I get the
> same behavior with BSD Find out of the box?
I don't know. But for tasks like you describe, I generally
cobble up (bourne)shell scripts, and keep them handy in my
~/bin/ folder. Heck, you could easily create aliases to
accomplish frequently used one-liners, and let us not
overlook your shells history.

But regarding your specific line above; maybe you mean:
# find -name /tmp/foo/* -delete, or
#find /tmp/foo/ -name * -delete
or for directories
# find /tmp/ -type d -name foo -delete
which wouldn't probably work, but is basically the
syntax your looking for. The key here, is -name. If
you get into the habit of using it, you'll forget
you need to add it, before you know it.
But for me; I'm still keen on cobbling up one-liners
for this sort of thing. :)

All the best.

--Chris
> 
> Thanks
> - m
> _______________________________________________
> freebsd-hackers at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"




More information about the freebsd-hackers mailing list