HELP Purge Large Maildir inbox

wazburn

Verified User
Joined
Nov 26, 2011
Messages
70
hi everyone.

im clearing my users mailbox with this script
Code:
#!/bin/sh

#Deletes emails older than this number of days
OLD_THAN_DAYS=30

for i in `ls /usr/local/directadmin/data/users`; do
{
       if [ ! -d /home/$i/Maildir ]; then
               continue;
       fi

       for file in `find /home/$i/Maildir -mtime +${OLD_THAN_DAYS} | grep -E '/cur/|/new/'`; do
       {
               rm -fv $file;
       };
       done;
};
done;
exit 0;

however it seems that hangsup due of the large size of my users inbox (Argument list too long)

How can I insert this in the script?:

Code:
find . -type f -delete
 
change it to

Code:
find /home/$i/Maildir -mtime +${OLD_THAN_DAYS} | grep -E '/cur/|/new/' | xargs rm -rf
 
Last edited:
You can also change the block:
Code:
       for file in `find /home/$i/Maildir -mtime +${OLD_THAN_DAYS} | grep -E '/cur/|/new/'`; do
       {
               rm -fv $file;
       };

By:
Code:
find /home/$i/Maildir/{new/,cur/} -type f -mtime +${OLD_THAN_DAYS} -delete
 
thank you, a little confuse, is this correct?

#!/bin/sh

#Deletes emails older than this number of days
OLD_THAN_DAYS=10

for i in `ls /usr/local/directadmin/data/users`; do
{
if [ ! -d /home/$i/Maildir ]; then
continue;
fi

for file in `find /home/$i/Maildir/{new/,cur/} -type f -mtime +${OLD_THAN_DAYS} -delete`; do
{
rm -fv $file;
};
done;
};
done;
exit 0;
 
thank you, a little confuse, is this correct?
...

It's not correct...

You can simply use:

Code:
#!/bin/sh

#Deletes emails older than this number of days
OLD_THAN_DAYS=30

find /home/*/Maildir/{new/,cur/} -type f -mtime +${OLD_THAN_DAYS} -delete

exit 0;

If you want to list the files before deleting, just remove the parameter "-delete" at the end of line.
 
Back
Top