On 2008-10-17 11:30, Jussi Hirvi wrote:
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.
Is there a way to go round this problem?
I have CentOS 5.2.
I believe you gave a bad example! In the command
rm -rf /var/amavis/tmp
the argument list is not at all "very long". However if you did:
rm -rf /var/amavis/tmp/*
then the argument list could be very long depending on the number of entries there are in the subdirectory.
You have to understand that globbing is done by the shell before starting the command. The result of the glob is what makes the "argument list too long"; it needs to fit in a buffer (about 128K bytes on a default CentOS install I believe).
If you want the to remove the subfolders and files, and not the parent folder itself, on CentOS 5, try this:
cd /var/amavis/tmp rm -rf *
Doing a "cd" makes the resulting of the globbing much shorter, maybe fixing your problem already.
If still too long, then try:
find . -maxdepth 1 -exec rm -rf {} +
You could even try things like:
cd /var/amavis/tmp rm a* rm *0 ...etc...
Any glob pattern resulting in less arguments for the command to avoid overflowing the 128K buffer is good.
On CentOS 4, the '+' variant of -exec does not exist, and you need to do:
find . -maxdepth 1 -exec rm -rf {} ; # one rm command for each arg or find . -maxdepth 1 -print0 | xargs -0 rm -rf # less resource intensive