Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

How to delete all mails on server older than X years..

Discussion in 'E-mail Discussion' started by ramystyle, Apr 6, 2008.

  1. ramystyle

    ramystyle Well-Known Member

    Joined:
    Feb 9, 2004
    Messages:
    64
    Likes Received:
    0
    Trophy Points:
    156
    Location:
    Montreal
    Hi,

    Is there a script for whm that deletes all mails older than XX years for all accounts on the server ?

    Thanks !
     
  2. WebScHoLaR

    WebScHoLaR Well-Known Member

    Joined:
    Dec 14, 2005
    Messages:
    511
    Likes Received:
    3
    Trophy Points:
    168
    Location:
    Planet Earth
    If the files haven't been accessed and have the older timestamp then you can delete the emails using find command.We will look for any files that are more than 2 years (2*365=730 days) old. A simpler command can be as but it needs to be further modified as per requirements.

    find /home/*/mail -type f -mtime +730 | xargs rm -vf

    You can set it as cron. Before running the command you should see what find command finds:

    find /home/*/mail -mtime +730 > /home/emails.list
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice