Error: Argument list too long
The maximum length of the command line argument is limited to *128k* within the Linux kernel:
- grep ARG_MAX /usr/include/linux/limits.h
#define ARG_MAX 131072
This annoying limitation usually manifests itself when the rm command is being used to delete a huge directory of unwanted files. The shell fails to invoke a command altogether if the ARG_MAX limit is exceeded:
rm * sh: /bin/rm: Argument list too long
A workaround is to use the find command to invoke the ?rm command with each argument individually:
find ./ -name '*' -print0 | xargs -0 -n 10 rm
note: Using "-print0" has additional benefit that it handles white space in filenames properly.
The limit affects the execve() kernel function, which is utilized by all other exec() functions (execl, execlp, execle, etc). The function works is by creating a 128K buffer at the top end of the memory space and copying the command line and environment for the new process into this space. The kernel then loads the new program into memory, sets its argv and envp pointers, and jumps to to program entry point. The "Argument list too long" error message is caused by the !E2BIG error code, being returned by the execve() function, when it is unable to fit the supplied argument list and environment into the 128K buffer.