Email can backup to the point where
rm -r -f *
doesn't work because there are too many spam emails in the directory.
Even the ls -al and du commands can fail, or take a really long time to return their results.
cp4:/home/answersl/mail/cur # rm -r -f * -bash: /bin/rm: Argument list too long
This command can give you an idea of the number of files in the directory:
find . | nl | tail
I had over 246,000 files backed up in one of the directories. The directory file itself was over 12MB!
total 9156 drwxrwx--- 7 characte characte 224 Nov 25 22:04 . drwx--x--x 11 characte characte 464 Dec 30 04:52 .. drwx------ 5 characte characte 120 Jan 14 2008 .maildirsize drwx------ 2 characte characte 48 Jan 14 2008 cur -rw------- 1 characte characte 3013 Dec 14 12:53 maildirsize drwx------ 2 characte characte 9371800 Dec 14 12:53 new drwx------ 2 characte characte 48 Dec 14 12:53 tmp |
total 15761 drwxrwx--- 7 hist11 hist11 184 Dec 17 2008 . drwx--x--x 13 hist11 hist11 536 Dec 30 04:52 .. drwx------ 5 hist11 hist11 120 Jan 14 2008 .maildirsize drwx------ 2 hist11 hist11 48 Dec 29 2007 cur drwx------ 2 hist11 hist11 16138472 Aug 20 2008 new drwx------ 2 hist11 hist11 48 Aug 20 2008 tmp |
In this case, you must use a simple script to iterate through smaller subsets of the list of files:
cd /home/answersl/mail/new find . > ../new.lst for g in 1 2 ; do for h in 0 1 2 3 4 5 6 7 8 9 ; do for i in 0 1 2 3 4 5 6 7 8 9 ; do for j in 0 1 2 3 4 5 6 7 8 9 ; do for k in 0 1 2 3 4 5 6 7 8 9 ; do echo $g$h$i$j$k ; rm -r -f `grep $g$h$i$j$k ../new.lst` ; done ; done ; done ; done ; done
This can also happen in the mail/cur directory. For this directory, all files might begin with the same first digits, like 1195922023.001663.mbox:2. But my cur file only had 23748 files in it, so we can use a smaller search space:
cd /home/answersl/mail/new find . > ../new.lst for h in 0 1 2 3 4 5 6 7 8 9 ; do for i in 0 1 2 3 4 5 6 7 8 9 ; do for j in 0 1 2 3 4 5 6 7 8 9 ; do for k in 0 1 2 3 4 5 6 7 8 9 ; do echo $h$i$j$k ; rm -r -f `grep $h$i$j$k ../new.lst` ; done ; done ; done ; done
or even just 3 digits:
cd /home/answersl/mail/new find . > ../new.lst for i in 0 1 2 3 4 5 6 7 8 9 ; do for j in 0 1 2 3 4 5 6 7 8 9 ; do for k in 0 1 2 3 4 5 6 7 8 9 ; do echo $i$j$k ; rm -r -f `grep $i$j$k ../new.lst` ; done ; done ; done
You may still get "argument list too long" when running this, but run it a second time, and it should finish the deletions. Or after the first run, you could try rm -r -f * again.
To see which accounts have too much spam backed up, you can use this:
cd /home for i in * ; do echo $i ; du -s $i/mail ; done
This may still take a while if there are really large directories. A quicker way is to just get a count of files:
cd /home for i in * ; do echo $i ; find $i/mail/. | nl | tail -n 1 ; done
Before I started this delete du /home showed 64197836 used. Afterwards, it was down to 63288728, a savings of 700mb.