Argument list too long
From Helpful
This error is technically pretty accurate, though it could be more verbose. It actually means that the shell-expanded argument list is too long for a chunk of kernel memory reserved for it (...specifically the environment + command line and probably some other details), usually something like 128KB, hard-coded in the kernel.
Bash and other shells expand shell globs (usually the cause is a *) before it executes a command (because most commands do not expand globs). When you have a large directory, something like "cp * backup/" would be rewritten with all the files in the current directory, then handed to a program. Since that start is kernel-mediated, the list of files needs to be handed to it, and the process will bork if the expanded string doesn't fit in the mentioned temporary space. I call that a design flaw - I don't see why the string can't be allocated on the spot - but it's currently just a fact of shell life.
There are various workable solutions:
- The low-brainer way is to shorten the expanded strings by making smaller globs. For example,
mv [a-d]* /elsewhere mv [e-h]* /elsewhere mv [i-k]* /elsewhere
...and so on, which will result in shorter lists and work.
Your options are, roughly (roughly ordered from probably-handiest to more-of-a-pain):
- find . | xargs echostyle, which is safer when it uses null delimiting:
- find . -print0 | xargs -0 echo(See also find and xargs)
-
- find -exec echo \{\} \;(I always seem to mess up its argument escaping, though, which differs between shell use and shell script use)
- ls | while read filename ; do echo $filename; done(specifically for bourne-type shells)
- Recompiling the kernel with a larger MAX_ARG_PAGES.
Of course, you dont' know how much you'll need, and this memory is permanently inaccessible for anything else, so it's not the best solution.
Note that most of these split the set of files into smaller sets, and execute something for each of these sets. In some cases this significantly alters what the overall command does.
Categories: Unices | Error | Workaround

