Efficient log management helps in maintaining disk space and improving observability. This guide covers how to find, inspect, and manage old Nginx logs.
find /etc/nginx/log/ -name "*.gz" -mtime +NReplace
Nwith the number of days.
# Logs older than 30 days
find /etc/nginx/log/ -name "*.gz" -mtime +30
# Logs older than 7 days
find /etc/nginx/log/ -name "*.gz" -mtime +7find /etc/nginx/log/ -name "*.gz" -mtime +30 -lsfind /etc/nginx/log/ -name "*.gz" -mtime +30 | wc -lfind /etc/nginx/log/ -name "*.gz" -mtime +30 -printfind /etc/nginx/log/ -name "*.gz" -mtime +30 -deletefind /etc/nginx/log/ -type f -empty -name "*.log"find /etc/nginx/log/ -type f -empty -name "*.log" -delete- Always test with
-printbefore using-delete - Consider compressing instead of deleting:
find /etc/nginx/log/ -name "*.log" -mtime +7 -exec gzip {} \;- Set up monitoring for log directory size:
du -sh /etc/nginx/log/Check when logs were last rotated:
ls -lth /etc/nginx/log/*.gz | head -n 5