The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

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

  1. ramystyle

    ramystyle Well-Known Member

    Joined:
    Feb 9, 2004
    Messages:
    64
    Likes Received:
    0
    Trophy Points:
    6
    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:
    2
    Trophy Points:
    18
    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
     
Loading...

Share This Page