5 ms·
The -delete option is not available on all UNIX systems, as it's not part of the POSIX spec (http://pubs.opengroup.org/onlinepubs/009604599/utilities/find.html
by nuxi 15y ago
The -delete option is not available on all UNIX systems, as it's not part of the POSIX spec (http://pubs.opengroup.org/onlinepubs/009604599/utilities/find.html http://pubs.opengroup.org/onlinepubs/009604599/utilities/fin...).
(Also, rant rant, I really don't understand why find was extended with -delete in the first place. What's next, "ls --delete" or maybe "cat --grep"?)
- RexRollman 15y agoI did a quick look online to see who has it. GNU, DragonFly BSD, NetBSD, and FreeBSD all have a -delete option. OpenBSD seems to be the only one that doesn't (although its online manpage does give examples on how to do it with -exec and piping to xargs).
- nuxi 15y agoThat's basically two flavours of UNIX (Linux and BSD), but that's OK - others are unfortunately either dead or dying. The UNIX family tree (http://www.levenez.com/unix http://www.levenez.com/unix) has been shrinking so rapidly in the last few years, that the current situation looks like the early years.
- RexRollman 15y agoSince the BSDs are all independently developed, I don't consider them to be one Unix, even though they share ancestry.
- jfb 15y agoThe orthogonality ship has sailed with Unix, for better or (IMHO) for worse. The Unix Haters were right about this, among other things, and the sections of the handbook about the shell are still valid, even as time and Moore have rendered others quaint.
- nuxi 15y agoFor worse, I concur. I still fire up my SGI boxes once in a while to remind myself things didn't use to/don't have to be as binary as they mostly are today (Linux vs BSD, iOS vs Android, Intel vs AMD etc.). That, and to run electropaint, of course. =)
- ars 15y ago-delete was added to find because of the race condition with doing it using xargs. See section 9.1.5 http://www.gnu.org/software/findutils/manual/html_node/find_html/Deleting-Files.html http://www.gnu.org/software/findutils/manual/html_node/find_...
- nuxi 15y agoThat was already fixed with -print0 | xargs -0, but then this solution is dismissed with "The problem is that this is not a portable construct;...". The -delete isn't either, so this is a straw man argument, although it probably is the most efficient and secure of all.
- ars 15y agoRead it again. -print-0 | xargs -0 does not fix the race condition. The problem is someone can swap in a symlink after the find, and before the xargs.
- nuxi 15y agoI'll have to run some more tests, but I can't see how -delete would help in that case .
- ars 15y agoBecause find changes to the directory first (carefully not following symlinks), and then deletes the file from there. It does not delete the file using the entire path (which may contain a sudden symlink). It's not possible to do this safely using xargs. Take a look also at -execdir which does the same thing - changes to the directory first, and runs things from there. -exec is not safe and should not be used. xargs is not safe if you are running against a directory not your own. You should use find and -execdir instead. Yes, the original authors of posix made a mistake here. > Also, rant rant, I really don't understand why find was extended with -delete in the first place. I'm hoping you understand it now.