Question: My logs are eating disk space. How do I compress old ones and keep only 30 days?
Try: find /var/log/app -name '*.log' -mtime +7 -exec gzip {} \; && find /var/log/app -name '*.log.gz' -mtime +30 -delete
Info: Compresses logs older than 7 days with gzip to save disk space, then deletes .log.gz archives older than 30 days to enforce retention.
Examples:
- $
logrotate -f /etc/logrotate.conf# Force run system log rotation - $
find /var/log -size +100M -exec truncate -s 0 {} \;# Emergency: truncate huge log files - $
journalctl --vacuum-time=30d# Purge systemd journal logs older than 30 days
Note: Use logrotate via /etc/logrotate.d/ for automated log management. For systemd journals, use --vacuum-size or --vacuum-time. The -mtime +7 test is based on whole 24-hour periods, so it can select files somewhat older than exactly 7 days.
Leave a Reply