A simple bash script that deletes log files older than 14 days from standard Linux and ZimaOS paths, helping keep your server's disk usage under control. Made with laziness by Server Log Cleaner Dev team(me) 🦥
Make the script executable and run it:
chmod +x Code-log-Cleaner.sh
sudo ./Code-log-Cleaner.shAlways do a dry run first to preview what will be deleted before actually removing anything:
sudo ./Code-log-Cleaner.sh --dry-run| Flag | Description |
|---|---|
--dry-run |
Preview files that would be deleted without removing anything |
--help |
Show usage information |
By default the script scans these directories:
| Path | Purpose |
|---|---|
/var/log |
Standard Linux system logs |
/root/.casaos/logs |
ZimaOS / CasaOS core logs |
/var/lib/casaos/logs |
ZimaOS service logs |
/DATA/AppData |
Docker app data |
It only targets files with log-related extensions (.log, .gz, .old, and numbered rotations like .1–.5), so your actual data files are safe.
At the top of the script you can change:
MAX_AGE_DAYS— how old a file must be before it's deleted (default:14)DRY_RUN— set totrueto always run in preview mode (default:false)LOG_DIRS— add or remove directories to scanLOG_PATTERNS— add or remove file extensions to target
To run the script automatically every Saturday at 3 PM:
sudo crontab -eAdd this line:
0 15 * * 6 /path/to/Code-log-Cleaner.sh >> /var/log/log_cleaner.log 2>&1
- Bash
sudo/ root accessnumfmt(part of GNU coreutils, installed by default on most Linux systems)
- This has been tested, and it works well
- The amount it cleans will probably fill up after a couple hours idk
- Friend that tested it said that there were so many logs on his server it filled up again after 10 seconds