This set of scripts automatically cleans up your Downloads folder by removing files that are older than 30 days.
- Only removes files older than 30 days
- Skips files that are currently in use
- Logs all actions for reference
- Runs automatically once per day at 1:00 AM
- Can be run manually at any time
-
Make both scripts executable:
chmod +x cleanup_downloads.sh setup_cleanup_job.sh -
Run the setup script to install the automatic job:
./setup_cleanup_job.sh
You can run the cleanup script manually at any time:
~/bin/cleanup_downloads.sh
Logs are stored in:
~/Library/Logs/cleanup_downloads.log- Main cleanup log~/Library/Logs/cleanup_downloads_error.log- Error log for scheduled job~/Library/Logs/cleanup_downloads_output.log- Output log for scheduled job
To change the number of days before files are deleted, edit the DAYS_OLD variable in ~/bin/cleanup_downloads.sh.
To uninstall:
launchctl unload ~/Library/LaunchAgents/com.user.cleanupdownloads.plist
rm ~/Library/LaunchAgents/com.user.cleanupdownloads.plist
rm ~/bin/cleanup_downloads.sh