I looked up on how to do this and it says to use cron, I've never used cron, so how would I go about doing this?
- I need them to delete every time it exceeds a certain folder size
- I need only .jpg files to be deleted
Webserver auto delete files
- sevensrequiem
- A semi-regular
- Posts: 17
- https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
- Joined: Sun Mar 31, 2019 5:52 pm
- Location: Missouri, USA
- Contact:
Re: Webserver auto delete files
A shell command like this should do what you want in terms of the actual deletions.
Replace 1000 with the size in bytes that you want to be your threshold for triggering the cleanup.
Replace ~/public/example with the actual folder name that you want to go through (in both places). It should start with ~/ because that is your home folder.
du --max-depth=0 ~/public/example | expr `awk {'print $1'}` \> 1000 && find ~/public/example -name "*.jpg" -delete
To make that into a cron entry, you need to edit your crontab and enter the command prefixed by when you want it run, per the cron documentation. For instance, to make it run every morning at midnight, you could use this entry:
@daily du --max-depth=0 ~/public/example | expr `awk {'print $1'}` \> 1000 && find ~/public/example -name "*.jpg" -delete
Replace 1000 with the size in bytes that you want to be your threshold for triggering the cleanup.
Replace ~/public/example with the actual folder name that you want to go through (in both places). It should start with ~/ because that is your home folder.
du --max-depth=0 ~/public/example | expr `awk {'print $1'}` \> 1000 && find ~/public/example -name "*.jpg" -delete
To make that into a cron entry, you need to edit your crontab and enter the command prefixed by when you want it run, per the cron documentation. For instance, to make it run every morning at midnight, you could use this entry:
@daily du --max-depth=0 ~/public/example | expr `awk {'print $1'}` \> 1000 && find ~/public/example -name "*.jpg" -delete