Bugzilla – Bug 54
Argument list too long errors
Last modified: 2001-10-29 01:51:02 MST
"Argument list too long" error messages: I am developing an application in Python which does a system call to sudo to allow it to list files in directories. Some directories have almost 10,000 files in them. '*' expands this with paths creating a huge string. Yes, this does seem insanely large, but the point is that 'sh' will process this string fine and 'sudo' will not. It seems to me ideally 'sudo' would have the same limit that 'sh' has. "It's not a bug, it's a feature!"
Sudo does not have an arbitrary limit on the length of command line arguments. This error is most likely coming from the kernel (execvp is returning E2BIG) before sudo is even run. I suspect if you run the ls w/o sudo and are careful to make sure /bin/ls is being run and not a shell builtin you will get the same behavior. I use tcsh, which has a builtin ls. I was able to do an ls of all my mail messages in all folders using the tcsh builtin ls but doing "sudo ls Mail/*/*" or /bin/ls Mail/*/*" yielded the dreaded "Argument list too long". The kernel does impose a limit to the size of the arguments passed to the exec() family of functions (ARG_MAX, 256KB on OpenBSD) and that is what you are running up against. The workaround is to use xargs(1).