Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Remove files via cronjob?

Discussion in 'General Discussion' started by graphicsarea, Nov 3, 2018.

Tags:
  1. graphicsarea

    graphicsarea Registered

    Joined:
    Nov 3, 2018
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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.
     
  2. rpvw

    rpvw Well-Known Member

    Joined:
    Jul 18, 2013
    Messages:
    1,088
    Likes Received:
    442
    Trophy Points:
    113
    Location:
    Spain
    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
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    #2 rpvw, Nov 3, 2018
    Last edited: Nov 3, 2018
    cPanelMichael likes this.
  3. cPanelMichael

    cPanelMichael Technical Support Community Manager Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    47,555
    Likes Received:
    2,182
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello @graphicsarea,

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

    Thank you.
     
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice