rm argument list too long find and xargs
Eric Battersby
gyre-Ja3L+HSX0kI at public.gmane.org
Wed Apr 14 04:32:50 UTC 2010
On Tue, 13 Apr 2010, D. Hugh Redelmeier wrote:
> | From: Chris F.A. Johnson <chris-E7bvbYbpR6jSUeElwK9/Pw at public.gmane.org>
>
> | On Mon, 12 Apr 2010, Christopher Browne wrote:
> |
> | >
>
> | No, it is a kernel issue.
>
> See execve(2). See the section "Limits on size of arguments and
> environment". Only in recent versions of that manpage.
>
> It says that kernels prior to 2.6.23 the memory requirement for args +
> environment variables must be less than or equal to 32 pages. Pages
> might be 4KiB
>
> For 2.6.23 and later the limit is probably 1/4 the limit on stack size.
Interesting, but this is too recent to depend on generally.
For example, my latest CentOS is running 2.6.18 .
> | > a) find -name "pattern" | xargs rm
>
> As CFAJ said in another message later in this thread, one should always
> keep in mind that filenames might contain "magic" characters like space
> and write scripts that handle this case.
>
> And xargs is stupid about handling empty lists unless you tell it to
> be smart.
>
> find -name "pattern" -print0 | xargs --null --no-run-if-empty rm
Of course, programmers should know that this
is the best method, but it makes me question the
original design of 'xargs'.
WHY was it designed to break when arguments contains quote or
double-quote?
WHY was it designed to "be stupid" about handling empty lists,
by default?
As an exercise, a while back, I wrote my own version of xargs
(eg: myxargs) to handle all those weird cases, except newline,
just as a convenience and with very little code.
I wound up using it all the time and it has never let me down.
--
The Toronto Linux Users Group. Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
More information about the Legacy
mailing list