Intermediate LevelLinux Commands & SysAdmin
How does logrotate manage automatic log file rotation, compression, and deletion?
❓ Interview Prompt: Explain logrotate daemon, /etc/logrotate.conf, service config files (/etc/logrotate.d/), rotation directives (daily, rotate 7, compress, delaycompress).
Unmanaged application log files will eventually fill disk drives. 'logrotate' automates periodic log rotation, compression, and deletion:
Directives in '/etc/logrotate.d/myapp':
•
'daily' / 'weekly': Rotation frequency.
•
'rotate 14': Retain 14 archived log files before deleting oldest.
•
'compress': Compress rotated logs using gzip.
•
'missingok': Ignore missing log files without erroring.
Code Implementation Example
ini
# /etc/logrotate.d/nginx
/var/log/nginx/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 0640 www-data adm
sharedscripts
postrotate
systemctl reload nginx > /dev/null 2>&1
endscript
}💡Logrotate configuration rotating Nginx logs daily with compression.
🎯 Interview Key Takeaway
Configure logrotate rules in /etc/logrotate.d/ to automatically compress and purge application log files.
#logrotate#Logs#Log Rotation#Intermediate
Back to all Linux Commands & SysAdmin Questions→