rm argument list too long find and xargs
D. Hugh Redelmeier
hugh-pmF8o41NoarQT0dZR+AlfA at public.gmane.org
Tue Apr 13 04:27:26 UTC 2010
| 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.
| > 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
| Using + instead of \; tells find's -exec to behave in the same way as
| xargs:
|
| find -name "pattern" -exec rm {} +
Wow. I didn't know that. Should have been done years ago.
But the syntax is really stupid. That makes three reserved words:
{}, +, and ;. Bad bad design.
As I read the description, the mandatory {} must be followed immediately
by the + and that the + terminates the arguments to the flag. So this
would not be legal:
find -name "pattern" -exec echo rm {} silly +
Better would have been to use a new flag. Say -xargs (very
suggestive)!
find -name "pattern" -xargs rm {} \;
Bonus rule 1: if no {} is found, act as if one were found at the end.
Bonus rule 2: if no \; is found, act as if one were found at the end.
Then this would work. Isn't it nice?
find -name "pattern" -xargs rm
Both those bonus rules could and should apply to -exec too.
--
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