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
Please help.
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.
Sign up to join this communityYou can add a cronjob which will run at 5 PM daily which will find and remove all .zip files in the specified directory as:
find . -type f -name "*.zip" -exec rm -f {} \;
This will find all the .zip
files in the current directory and remove them; this DOES not include directories named *zip
You can put the above command in a shell script as it is and then run it via cron.
To add a cron, simply put the following in the file that opens up after typing crontab -e
:
0 17 * * * script.sh
Where script.sh
is the script containing that one line command.
Weekday
should have either 5 or 17 (consult with your hosting provider to clarify on that) and in the Minute
field, it should be 00
. In the Command
field, you need to put the command that I shared (find . -type f -name "*.zip" -exec rm -f {} \;
). Again, I'd recommend to ask your provider for how to set the time via GUI but the command should be the same.
public_html/ali/hi
when the command is called/run from something/public_html/ali/hi
: find something/public_html/ali/hi -type f -name "*.zip" -exec rm -f {} \;
; you can also put in the absolute path (from the terminal, run pwd
while you are cd'd into ...ali/hi
directory), the output is your absolute path to this directory. In this case, use: find absolute_path_here -type f -name "*.zip" -exec rm -f {} \;
change folder_path to your value
check cronjob installed: crontab -l