-
-
Notifications
You must be signed in to change notification settings - Fork 1
Linux logrotate Guide
Mattscreative edited this page Dec 5, 2025
·
2 revisions
Complete beginner-friendly guide to logrotate on Linux, covering Arch Linux, CachyOS, and other distributions including log rotation, configuration, and log management.
logrotate rotates, compresses, and manages log files.
Functions:
- Prevent disk full: Rotate logs before they grow too large
- Compress logs: Save disk space
- Archive logs: Keep old logs for reference
- Delete old logs: Remove logs after retention period
Why it matters:
- Disk space: Prevents logs from filling disk
- Organization: Keeps logs manageable
- Compliance: Maintains log history
Arch/CachyOS:
# Install logrotate
sudo pacman -S logrotate
# Enable service (if using systemd)
sudo systemctl enable logrotate.timerDebian/Ubuntu:
sudo apt install logrotateFedora:
sudo dnf install logrotateCheck logrotate:
# Check version
logrotate --version
# Check status
systemctl status logrotate.timerEdit config:
# Main config
sudo vim /etc/logrotate.confCommon settings:
# Rotate weekly
weekly
# Keep 4 weeks of logs
rotate 4
# Create new empty log
create
# Compress old logs
compress
# Delay compression
delaycompress
Per-application configs:
# Application configs
/etc/logrotate.d/
# List configs
ls /etc/logrotate.d/Create rule:
# Create rule file
sudo vim /etc/logrotate.d/myappBasic rule:
/var/log/myapp.log {
daily
rotate 7
compress
missingok
notifempty
}
Advanced options:
/var/log/myapp/*.log {
daily
rotate 30
compress
delaycompress
missingok
notifempty
create 0640 user group
sharedscripts
postrotate
/usr/bin/systemctl reload myapp
endscript
}
Test logrotate:
# Test configuration
sudo logrotate -d /etc/logrotate.conf
# Test specific config
sudo logrotate -d /etc/logrotate.d/myapp
# Force rotation (dry run)
sudo logrotate -f /etc/logrotate.confRotate manually:
# Force rotation
sudo logrotate -f /etc/logrotate.d/myapp
# Verbose output
sudo logrotate -v /etc/logrotate.d/myappCheck configuration:
# Test config
sudo logrotate -d /etc/logrotate.conf
# Check for errors
sudo logrotate -v /etc/logrotate.conf
# Check state file
cat /var/lib/logrotate/statusFix permissions:
# Check log file permissions
ls -la /var/log/myapp.log
# Fix ownership
sudo chown user:group /var/log/myapp.logThis guide covered logrotate installation, configuration, and log management for Arch Linux, CachyOS, and other distributions.
- Log Management - System logs
- System Monitoring - System monitoring
- System Configuration - System setup
-
logrotate Documentation:
man logrotate
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.