Celeb Glow
news | March 07, 2026

Cron job to delete files older than x days?

I'm currently using this cron job to delete stalled temp files in a particular location. How can I improve this to only delete files older than x days (e.g., 30 days)?

0 4 * * 0 /bin/rm -fv /home/*/tmp/Cpanel_*

1 Answer

You can use find:

find /home/*/tmp/Cpanel_*' -type f \! -newermt "month ago" -delete

find can be tricky, so do your homework reading about it and test well. The common practice is to test with a command that doesn't act on found targets, like ls or echo. find has some builtin commands you can use for testing. So you can start with this:

 find /home/*/tmp/Cpanel_*' -type f \! -newermt "month ago" -ls
8

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy