Drop huge amount of emails under linux

Last days I’ve run into an issue with customers email server. It was running very slowly so I’ve had to take a look at it.
Problem was caused by cron jobs sending error emails – 2 errors every 10 minutes.. since ’09..
This caused over 138,000(!) unwanted emails. I didn’t want to spend months at webmail deleting ~30 emails at once so I’ve quickly jump to shell and run rm *. I was quite suprised (I’m a linux noob) that it caused an Argument list too long error. find command ended up with the exactly same error message.

I thought I would try the workaround – bash script.

[~/mail]# nano remove.all
for file in ./cur/*
rm $file
echo removed $file
[~/mail]# chmod +x remove.all
[~/mail]# ./remove.all

After about 20 minutes script has ended and it worked as it supposed to. Hooray!

I know there should be much easier way like drop whole directory instead, point of this way is to try out bash loops.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.