Http://www.yunweipai.com/archives/558.html
The reason analysis of "Arg list too long" in Linux execution command error
Tuna Hand Scroll was published 3 years ago in operation and maintenance experience in 2012-09-15
Recently, a problem has been encountered with the SUSE Linux operating system: Perform RM * Delete all files in a folder containing tens of thousands of files times wrong "Arg list too Long", which eventually resulted in a deletion failure. Later looked at the data, after analysis found here are several technical points to note:
1. In the Linux operating system has limited the length of a single command line is 128KB, that is, 131072 bytes, while RM * This command in the deletion of all files, this * as a wildcard character will eventually be converted to the full path of the file, so that the bottom of the system will be RM * Converted to a command line exceeding 128KB in size, thus command execution failed;
2. Query the Linux operating system for a single command line length limit: The Linux operating system can perform getconf Arg_max, echo information is the limit of the number of bytes;
3. The Arg_max parameter is 1048320 bytes (1024KB) in Solaris, in Linux Chinese 131072 bytes (128KB);
4. The Arg_max parameter definition is in the kernel of the Linux/unix operating system.
Finally, the problem of RM * mentioned above can be solved by using the combination of pipe character and xargs to ensure that only one file is deleted per rm, so it is impossible to have a single command exceeding the length of 128KB characters:
# ls | Xargs RM