Keep growing log files in check by rotating, compressing and pruning them automatically. 16.11.2025 | reading time: 2 min Logs grow without asking; they fill disks and make troubleshooting harder. Learn how to rotate custom log files so they stay useful, lean and manageable, using practical examples you can run now. Rotate in Action Create a tiny test log and a logrotate rule, then force a rotation to see the sequence and files created. Example commands and expected output: ```bash mkdir -p /opt/myapp/log && echo "first-line" > /opt/myapp/log/app.log && for i in 1 2 3; do echo "entry $i" >> /opt/myapp/log/app.log; done cat /opt/myapp/log/app.log ``` Expected output: ```text first-line entry 1 entry 2 entry 3 ``` Now a minimal logrotate config and forced run: ```text /opt/myapp/log/app.log { daily rotate 7 compress missingok copytruncate } ``` Save that to `/etc/logrotate.d/myapp` and run: ```bash logrotate -f /etc/logrotate.d/myapp ls -l /opt/myapp/log ``` You will see `app.log` and a compressed rotated file such as `app.log.1.gz`, showing rotation worked. Tuning Rotation Pick options to match the application: use `copytruncate` when you cannot restart the writer, or rotate with `postrotate` scripts to tell the daemon to reopen files; use `size` to trigger rotation by bytes instead of time; set `rotate` to keep the desired number of archives; add `delaycompress` when the app keeps file handles open and you want the previous file compressed one cycle later. Bring Other Tools Not every environment uses logrotate: systemd journal uses `journald` and `journalctl --vacuum-size` to trim logs; web servers often ship `rotatelogs` for per-virtualhost rotation; specialized programs like `cronolog` and centralized collectors handle stream rotation or remote storage in large deployments. Next Steps Automate rotation in configuration management, monitor disk and archive policies, and test rotations regularly to avoid surprises; mastering log management reduces incidents and helps audits. Want a structured path? Deepen Linux skills and consider certifications like CompTIA Linux+ or LPIC-1 with intensive exam preparation at bitsandbytes.academy. Join Bits & Bytes Academy First class LINUX exam preparation. filesystem utilities scripting