My antispam system is configured to classify incoming messages and copy them to a particular sub-directory. As time pass more a more messages are accumulated in this folder. Recently I tried to eliminate old messages and I found myself with this:
/bin/rm: Argument list too long
And then I took a look at the directory and saw something like this:
ls -al | wc -l
58259
It seems that the rm command can’t deal with such number of arguments. Fortunately there are some workarounds for this problem.
ls | xargs rm
Or you can combine rm with find:
find . | xargs rm
It seems that this is a limit inside the kernel and not a limitation of rm or a limitation of the shell. On the other hand if the filenames have white spaces the best way is to do something like this:
Morpheo
Since the pruning of overcrowded quarantine directories is a pretty much recurring task, I have a handy shell function to do that (incorporates a basic sanity check, skips directories and dotfiles):
Hope it helps.
Kelas.