cPanel Erase Emails older than X amount of days – Tutorial

October 18th, 2012 admin Location: Raleigh, NC, Topic: Web Design | Digital Media

If you are a Linux admin and you would like to delete emails from a particular cpanel account without having to do it manually, you would do so directly via SSH.

The Problem:

The problem is that sometimes you want to only delete the emails that have some longevity. In other words, you may desire to delete only those emails that are older than x number of days. So how do you do that?

The Solution:

The solution is pretty simple. We are going to be using the find command from terminal.

So first, log into your server via ssh using terminal. Once there, locate the account that holds the emails in question. This accounts are usually located at: /home/name_of_account/mail/domain_name/

Use “cd” to go into the email account that you are about to delete emails from. You’ll see several folders, and in specific you’ll use two: /new and /cur

This two folders hold the emails for that particular account.

Now you can run the command that will list the emails that you want deleted. Please note, we are not deleting them just yet, we want to list them first to make sure we are finding the right ones.

find /home/name_of_account/mail/ -mtime +5 -type f -ls

Great that will show you the emails that you are about to delete in a list. Check them and make sure they are the ones you want to delete and then run the final command:

find /home/name_of_account/mail/ -mtime +5 -type f -delete

Also do the same by replacing /new with /cur as below:

find /home/name_of_account/mail/ -mtime +5 -type f -delete

So what is this command doing? First it finds in the given directory(/cur) the files (-type f) with a modified time in days (-mtime) of more than 5 (+5), then it deletes them.

Of course you can change the modified time to any number that you want, in this example I have used five days but of course you could use (+30) for a month or (+365) for a year, etc.

There you have it. That’s it. Please don’t hesitate to comment below if you found this helpful.

Until next time.

About the Author

Alex Centeno MBA., is an international creative director and digital media strategist. Currently residing minutes away from the Research Triangle Park (RTP) - North Carolina, and with over 10 years of interactive marketing training and experience, Alex leads Merkados' international clients to maximizing their online business strategies. One of Alex's biggest strengths is his world-class capacity to effectively combine interactive marketing, digital media design and web development.

You may find further information about Alex Centeno MBA. at: and Twitter.

Sobre el Autor

Alex Centeno MBA., Es un director creativo y estratega de medios digitales reconocido internacionalmente. En la actualidad reside a tan solo minutos del Research Triangle Park (RTP) - Carolina del Norte, y con más de 10 años de entrenamiento y experiencia en marketing interactivo, Alex lidera a los clientes internacionales de Merkados™ para maximizar sus estrategias de negocios en línea. Una de las mayores fortalezas de Alex es su capacidad global de combinar de manera efectiva, mercadeo interactivo, diseño de medios digitales y desarrollo web.

Para más información sobre Alex Centeno MBA. puede visitar: y Twitter.