The easiest way to delete files older than 'x' days via command line (therefore a cron job can be created to delete it daily) would be:
find /share/Download/messages* -mtime +5 | xargs rm -rf
Then crontab -e and add the following to the bottom
1 0 * * * find /share/Download/messages* -mtime +5 | xargs rm -rf
This will then keep the last 5 days worth of logs.
Good article on editing cron located here : http://wiki.qnap.com/wiki/Add_items_to_crontab
Thanks for this! I spent a lot of time looking for a command that is supported by Qnap without installing additional packages.
ReplyDeleteChanges made with crontab -e will not survive reboots, however. See https://wiki.qnap.com/wiki/Add_items_to_crontab
Oh, and if anyone new to Linux (like myself) needs a little more information: https://forum.qnap.com/viewtopic.php?f=185&t=126593&p=572821#p572821
DeleteThis solution doesn't work if file name have space.
ReplyDeleteIt could help me make the most of my nourishment and time alone. Eating carefully may help me know about sound nourishment and acknowledging sustenance.
ReplyDeleteTeraStation 5400RN 8TB NAS
@RafaĆ:
ReplyDeleteIf file name has space just use:
find "/share/Download/spaced messages*" -mtime +5 | xargs rm -rf
Well, that just deleted everything in my directory specified folders and all even though I had files on there less than 30 days old. I used +30.
ReplyDelete