Automatically delete files over one week old

Posted by cainram 
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.
Now, this forum is in read-only mode. You find details Details hereContinue on /r/PirateBox
Automatically delete files over one week old
August 11, 2016 09:15PM
What would be the best way to set up a Raspberry Pi(rate) Box to go through once a day and delete any uploaded files older than one week? Has anyone done this before?
Re: Automatically delete files over one week old
August 12, 2016 05:46PM
I'm not sure if this has been done before, however you could write a script to do it.
Look into Cron jobs. You could grab the "modified time" of the files in directory X and apply a command to them.

If you decide to write a script it would be nice to share it here.

Ubuntuhak, playing and tinkering with Ubuntu!
Create a cron to run once a day with this:
# sudo crontab -e

and then put this in:

* 22 * * * test > find /path/to/files* -mtime +7 -exec rm {} \;

This fires off daily at 10PM based on the server time.
Please be aware though, this may NOT work in all scenarios. I myself have a Piratebox that I carry on y person, and it gets plugged/unplugged at random times throughout the day. With no internet connection and no time server, it NEVER knows what time it is or how much time has passed. but an always on solution this would work for!