简体   繁体   中英

Deleting files from folder using cron job

I have a cron job setup to run at a set interval to remove images from a folder. The problem I can't solve is it removes my index. I need some help removing only file extensions such as .jpg, .png, .gif yet leaving my index.php file. The cron job I'm using now removes everything including my index.php allowing people to view the links in that folder. Can someone please tell me how to add extensions to delete while leaving my index or tell the cron job exclude my index file ? This is the cron I'm using.

rm -f /home/username/public_html/subfolder/filesfolder/*

You can add a cron for each extension thus:

rm -f /home/username/public_html/subfolder/filesfolder/*.jpg
rm -f /home/username/public_html/subfolder/filesfolder/*.png
rm -f /home/username/public_html/subfolder/filesfolder/*.gif
rm -f /home/username/public_html/subfolder/filesfolder/*.png

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM