Sunday 16 November 2014

Delete log files older than x days on QNAP NAS


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

6 comments:

  1. Thanks for this! I spent a lot of time looking for a command that is supported by Qnap without installing additional packages.

    Changes made with crontab -e will not survive reboots, however. See https://wiki.qnap.com/wiki/Add_items_to_crontab

    ReplyDelete
    Replies
    1. 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

      Delete
  2. This solution doesn't work if file name have space.

    ReplyDelete
  3. It could help me make the most of my nourishment and time alone. Eating carefully may help me know about sound nourishment and acknowledging sustenance.

    TeraStation 5400RN 8TB NAS

    ReplyDelete
  4. @RafaƂ:
    If file name has space just use:
    find "/share/Download/spaced messages*" -mtime +5 | xargs rm -rf

    ReplyDelete
  5. 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