One of my apps, YouTube Audio Downloader, has been gaining quite a bit of traffic lately. It's a website that lets you convert YouTube videos to MP3/M4A audio. The conversion happens completely on my server and a download link is provided to the user when finished. The files need to be stored temporarily on my server so the users can download them.
Initially, I just had a daily cron job that runs at midnight to clear my media folder. But due to the increased traffic and my cheap $5 DigitalOcean VPS which doesn't have much storage, the disk is getting close to filling up by the end of the day. So I changed my cron job to instead run hourly and delete those files that were last changed more than two hours ago. Two hours should be plenty enough time for the user to have finished downloading the file.
The command is a pretty simple one-liner, though I probably won't remember it so I'm making a note of it here for future reference:
find /webapps/youtubeadl/media -type f -cmin +120 -delete
This command basically just deletes all the files in my media folder where the last changed time is older than 120 minutes.
My YouTube Audio Downloader project is open-sourced, by the way. Check it out on GitHub.