"Argument list too long" error for `rm -rf *` on a directory with 4000 files

This is not an issue but a limit. You can use something like this:

find ./ -exec rm -rf {} \;

Or what is the matter of not using an alternative that does the job?


This is still a problem on all Unixes I know of, as well as Windows. It's really a limit on the number of bytes being passed on the command line, not the number of files or whatever.

Try getconf ARG_MAX to see the limit (in bytes) for your Unix. You can use the xargs command to work around such problems.


While I can't speak for other *nixs, AFAIK, this "issue" has always existed in Mac OS X.

ARG_MAX is defined as the following in /usr/include/sys/syslimits.h:

#define ARG_MAX   (256 * 1024)  /* max bytes for an exec function */

sysctl kern.argmax returns:

kern.argmax: 262144

(This is in Mac OS X 10.7.3; many of these types of limits have been increased gradually over the course of the lifetime of OS X).