Automatically empty recycle bin (the Trash folder)

This article explains how to empty only the Trash of mailboxes with a cPanel cron job. In Roundcube, Delete sends the message to the Trash. It keeps taking up space there until that folder is emptied.

What is it for?

The cron checks the Trash of all mailboxes in the account every day and deletes anything older than the time you specify. The example below leaves the last 5 days and deletes the rest.

  • It only acts on the Trash folder, saved on the server as .Trash.
  • The inbox, Sent, and the rest of the folders remain the same.
  • A crossed-out message in the inbox does not enter this deletion: it has to be in the Trash first.

Important: what this cron deletes cannot be recovered. The command must point to .Trash. If that part of the path is changed, it can delete mail that is still in use. The time is the server time.

Access: log in to cPanel from the client portal → Log in to cPanel, or at https://yourdomain.com/cpanel.

Create the job

  1. Open Advanced → Cron Jobs.

Trabajos de cron en la sección Avanzada de cPanel

  1. In Common Settings, choose one execution per day.
  2. To run it at 4:00, leave Minute at 0, Hour at 4, and Day, Month and Weekday at *.
  3. In Command, paste this line. The 5 is the days they are kept.
/usr/bin/find "$HOME/mail" \( -path '*/.Trash/cur/*' -o -path '*/.Trash/new/*' \) -type f -mtime +5 -delete

Formulario para añadir un trabajo de cron

  1. Click on Add New Cron Job.

To empty the entire Trash on each execution, remove -mtime +5 from the line and leave the rest the same. $HOME is the hosting account: the cron goes through the mailboxes of all domains in that account.

-mtime +5 deletes a file from the Trash when more than 5 24-hour days have passed since it entered there. A message deleted yesterday remains until reaching that deadline.

Common issues

  • The inbox is still full: those messages are not in the Trash. This cron doesn't see them.
  • I deleted an email today and it is still in the Trash: with +5 it waits for it to exceed 5 days. To empty all of it on each pass, remove -mtime +5.
  • Space was not freed instantly: the file was already deleted. The account usage indicator updates when the system measures it again.
  • A cron mail arrives with an error: the command has to be in a single line and the path has to keep saying .Trash.
  • It ran at another time: the 4 hour is the server time. If you chose the common settings and didn't change Hour, it stays at 0:00.

If the job appears loaded and the Trash is not emptied on the next pass, open a ticket from the client portal or consult through the site's online chat.

  • vaciado automático de papelera, vaciado carpeta trash, programar cron
  • 45 Users Found This Useful
Was this answer helpful?

Related Articles

How to delete messages using WebMail

This article explains how to view and delete messages in Roundcube, and how to delete them from...

Webmail - Unable to access my messages

This article explains why Webmail might not let you view or save messages, and how to check your...

How to save copies of sent messages using Webmail

This article explains how to save a copy of sent messages in Roundcube, the hosting's current...

Catch-all mailbox (Default Address)

This article explains what a catch-all mailbox is and how to enable or disable it using cPanel's...

How to enable SpamAssassin

This article explains how to enable the spam filter in cPanel so that new messages with a high...