graphicsarea

Registered
Nov 3, 2018
1
0
1
Turkey
cPanel Access Level
Website Owner
How to remove zip files in specific folder in my hosting by cron job?

I want to remove zip files in specific folder every day at 5:00PM

My directory (files) located in:
/home/site/public_html/pics/files/

Thanks.
 

rpvw

Well-Known Member
Jul 18, 2013
1,100
477
113
UK
cPanel Access Level
Root Administrator
You could use the following code, but it is important that you actually understand what it does and you don't just blindly copy and paste it .......
Code:
find /home/site/public_html/pics/files/ \( -name "*.zip" \) -type f -exec rm {} +
Warning - this will also recursively loop through all the folders below the defined folder as well

If you just want to limit the find to the configured folder use
Code:
find /home/site/public_html/pics/files/ -maxdepth 1  \( -name "*.zip" \) -type f -exec rm {} +
The best way of using this is to create a shell script and then call it by cron.

If you don't have access to shell, you might want to explore using php to do the same thing
See PHP: unlink - Manual

When you have decided on what script you are going to run, and have tested it, full details of how to add the cron job are available at Cron Jobs - Version 74 Documentation - cPanel Documentation
 
Last edited:
  • Like
Reactions: cPanelMichael

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,268
463
Hello @graphicsarea,

I concur with @rpvw here. Let us know if you have any additional questions.

Thank you.