Quick Linux Tip #108:
Question: My logs are eating 50GB. How do I compress all old ones in one pass?
Try: sudo find /var/log -type f \( -name '*.log' -o -name '*.log.?' \) -mtime +7 ! -name '*.gz' -exec gzip -9 {} +
Info: Recursively finds and compresses log files older than 7 days using maximum compression (-9).
Examples:
- $
sudo find /var/log -name '*.log' -mtime +30 -delete# Delete log files older than 30 days - $
sudo logrotate -f /etc/logrotate.conf# Force manual execution of logrotate - $
sudo journalctl --vacuum-size=1G# Shrink systemd journal logs to a 1GB limit
Note: Text logs typically compress by 90%+. Always use logrotate or copy/truncate strategies for production logs rather than compressing active files directly.
Leave a Reply