Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Ouch... don't do that' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Ouch... don't do that
Authored by: merlyn on Jan 30, '03 11:16:05AM
Because OSX filenames commonly contain whitespace, doing anything with find and xargs requires the NUL-delimited mode:
find ... -print0 | xargs -0 ...


This is the same mistake that Apple made for the iTunes 1.1 update that deleted entire volumes if they were named with a space-included name.


Do not be as dumb as Apple here.

[ Reply to This | # ]

please, please, please...
Authored by: gvitale on Jan 30, '03 11:31:17AM

Could you explain that in more details?
It looks like an important point for correct find usage...
Thanks in advance.
gaetano



[ Reply to This | # ]
why using -0 and -print0 matters
Authored by: merlyn on Jan 30, '03 01:17:57PM
By default, xargs takes any whitespace in its input to delimit between entries. This is fine for traditional typical Unix filenames, but has always been a problem for security-minded folks who know that filenames can contain arbitrary whitespace (spaces, tabs, newlines).


In fairly modern versions of xargs (including the version shipped with OSX), the -0 switch can be added, which overrides the delimiter to be strictly and only the ASCII NUL byte (which cannot ever appear within a filename, because all Unix system calls are NUL-terminated strings). Now, this won't work with traditional find ... -print, but most modern find commands have also been updated to include -print0, which puts a NUL byte between entries -- not a newline!


So, when you use them together, you get a nice handoff solution for what was formerly a security nightmare. As the good folks at Apple found out for the iTunes update... whitespace matters!

[ Reply to This | # ]