[CentOS] ls and rm: "argument list too long"

Sun Oct 19 01:13:18 UTC 2008
mouss <mouss at netoyen.net>

Jussi Hirvi a écrit :
> Since when is there a limit in how long directory listings CentOS can show
> (ls), or how large directories can be removed (rm). It is really annoying to
> say, for example
> 
>     rm -rf /var/amavis/tmp
> 
> and get only "argument list too long" as feedback.


I doubt this. "argument list too long" is a shell error, and in your
command the shell doesn't see many arguments.

I guess you want to remove amavisd-new temp files and you did
	rm -rf /var/amavis/tmp/*

In this case, the shell would need to replace that with
	rm -rf /var/amavis/tmp/foo1 /var/amavis/tmp/foo2 ....
in which case, it needs to store these arguments in memory. so it would
need to allocate enough memory for all these before passing them to the
rm command. so a limitation is necessary to avoid consuming all your
memory. This limitation exists on all unix systems that I have seen.


> 
> Is there a way to go round this problem?
> 

Since amavisd-new temp files have no spaces in them, you can do
	for f in in /var/amavis/tmp/*; do rm -rf $f; done
(Here, the shell does the loop, so doesn't need to expand the list at
once).

alternatively, you could remove the whole directory (rm -rf
/var/amavis/tmp) and recreate it (don't forget to reset the owner and
permisions).



> I have CentOS 5.2. 
>