Skip to content

Cronjob to remove files older than X days (if file uploading is enabled)

Vitor Luis edited this page Apr 15, 2020 · 2 revisions

This was tested in Ubuntu. For other distros check the distro documentation

If you want to save disk space but still allow your users to share files, you can add this cronjob to your shell user:

NOTE: replace all occurrences of $USER with your shell user name

  • As your shell user type: crontab -e
  • Add the following to the crontab (on a new line): 0 0 * * * find /home/$USER/.thelounge/uploads/* -mtime 1 -delete >/dev/null 2>&1 (this will run every day at midnight and will delete all folders and files older than 1 day)
  • Press CTRL+S followed by CTRL+X to save the cronjob (assuming you're using nano)

And that's all. From now on all the files uploaded by your users will be deleted after 24h, therefore saving your disk space and without the need to do it manually.