Limitations on a command line
Cathey, Jim
jcathey at ciena.com
Wed Feb 2 18:48:46 UTC 2011
>> Whereas "find /tmp -mindepth 1 -maxdepth 1 ! -type d -print0 \
>> | xargs -r0 rm -f" will succeed. More
>> complicated, to be sure, but more robust.
>Jim - I'm quite interested in this issue - a customer has just forced
us
>to up the spec on our data logger so it may have to delete 1000+ files
at
>once from a log area. I guess that will have the possibility to run
into
>this issue.
Absolutely the sort of area where find/xargs will not run into
trouble, yet other methods might have trouble. find -exec will
work, but will be slower than find in conjunction with xargs.
>I've just done a pile of googling and now vaguely understand that line!
>is the -r0 a typo?
Nope! -r tells xargs not to run the target command if there are
no additional arguments fed from the pipe. Avoids things like "rm -f"
being executed at the end. One could argue that this should have
been xargs' default behavior from the very beginning, but for
whatever reason it is not.
The -0 works in conjunction with -print0 to handle filenames with
spaces in them. There are only two characters that literally cannot
be part of a filename: a slash (which is a path separator), and a NULL.
By using the NULL as a delimiter, literally _any_ weird-ass character
found in a filename will still be properly processed.
I just happen to use -r0 canonically, always have. Getopt likes it
just fine.
-- Jim
More information about the busybox
mailing list