Argument list too long

Symptom

You may encounter the following error:

$ mv * /tmp/
bash: /bin/mv: Argument list too long
$ cp * /tmp/
bash: /bin/cp: Argument list too long
$ rm *
bash: /bin/rm: Argument list too long

Reason

  • The traditional Unix operating system kernel has a fixed limit of memory available for program environment and argument list combined. Into this combined program environment and argument space all of the environment and all of the command line arguments must be fit. If they don't fit then the external program execution will fail. In the above example the * is expanded by the shell into a literal list of filenames to be passed as command line arguments to the mv program. If the number of files in the current directory to be expanded is larger than this fixed buffer space including the environment space then they won't fit. In that case it is impossible to execute the program with the specified list of arguments and the current environment size.

  • The value of ARG_MAX limits the maximum size of the buffer. The getconf command may be used to print the currently implemented limit:

    $ getconf ARG_MAX
    131072

Note

The Linux kernel has removed the classic ARG_MAX limitation. See the variable length argument support changeset. This was released with the linux-2.6.23 kernel. It will eventually propagate into the release software distributions which include it. Note that glibc's getconf ARG_MAX hasn't caught up yet and still reports a fixed value.

Solutions

ArgumentListTooLong (last edited 2009-08-04 06:08:57 by ZhigangWang)