delete old cached files by cpanel cronjob

nh22h55

Registered
Nov 9, 2019
1
0
1
uae
cPanel Access Level
Root Administrator
hello every body
i want to know how can i delete my old cached files in one directory by setting cronjob for 4:00 am


if i can do it by date, it will be awesome! like delete old file more than 1 week

and if it cant be possible, so delete all my cache file in the cache folder every 1 week


thank you everyone
 

GOT

Get Proactive!
PartnerNOC
Apr 8, 2003
1,739
302
363
Chesapeake, VA
cPanel Access Level
DataCenter Provider
You can add this cron as root with crontab -e

0 4 * * * find /path/to/files* -mtime +7 --delete

This will at 4 am every day delete the files in the path older than seven days.
 

cPanelLauren

Product Owner
Staff member
Nov 14, 2017
13,295
1,255
313
Houston
You can add this to the cPanel interface for the account you're wanting to delete the cache files for. You do want to be careful you're only deleting the cache files specifically as well.
 

quietFinn

Well-Known Member
Feb 4, 2006
1,222
87
178
Finland
cPanel Access Level
Root Administrator
I would suggest using this command:

Code:
find /path/to/files -type f -mtime +7 -exec rm -f {} \;