Learn how to keep log directories tidy by rotating, compressing and archiving logs with logrotate. 16.11.2025 | reading time: 2 min Log files grow without mercy; logrotate lets you rotate, compress and remove old logs automatically so disk space stays predictable. A practical rotation example Create a small config and run logrotate to see results; below is a sample file and a short dry-run followed by a forced rotation to inspect outcomes: ```/etc/logrotate.d/myapp /var/log/myapp/*.log { daily rotate 7 compress missingok create 0640 root adm postrotate systemctl reload rsyslog >/dev/null 2>&1 || true endscript } $ logrotate -d /etc/logrotate.d/myapp reading config file /etc/logrotate.d/myapp Handling 1 logs rotating pattern "/var/log/myapp/*.log" on frequency 1 day (24 hours) $ logrotate -f /etc/logrotate.d/myapp $ ls -l /var/log/myapp -rw-r--r-- 1 root adm 0 Jun 1 12:00 myapp.log -rw-r--r-- 1 root adm 1234 Jun 1 12:00 myapp.log.1.gz ``` Options that change behavior Use short directives to alter rotation: "daily", "weekly" or "size" to trigger; "rotate N" to keep N archives; "compress" saves space; "dateext" adds dates; "copytruncate" helps when he cannot signal the process to reopen files; "postrotate" runs commands after rotation; "missingok" avoids errors when logs are absent; "notifempty" skips empty logs; combine them to suit the application and the retention policy. Where logrotate fits in the stack logrotate manages files produced by syslog daemons, applications and scripts; pair it with rsyslog or systemd-journald for collection, cron for scheduling custom runs, and standard compressors like gzip for storage efficiency; moreover, check the state file under /var/lib/logrotate/status to debug timing and keep rotation deterministic. Keep logs manageable Rotate early, compress aggressively, and purge old data; a small config prevents a full filesystem and makes incident investigations faster; if you want to dive deeper, study log collection, retention policies and automation — consider preparing for CompTIA Linux+ or LPIC-1 with intensive exam preparation at bitsandbytes.academy to solidify your Linux skills. Join Bits & Bytes Academy First class LINUX exam preparation. utilities backup storage scripting troubleshooting