How do you delete log files larger than 50MB and older than 30 days?
⚡
Quick Answer
Use find with size and mtime filters and the delete action: find /var/log -type f -size +50M -mtime +30 -delete. Test first by replacing -delete with -print.
Detailed Answer
The predicates combine: -type f (files only), -size +50M (larger than 50MB), -mtime +30 (modified more than 30 days ago), and -delete removes matches. Always dry-run with -print first to confirm the match set, and prefer logrotate for ongoing log management rather than ad-hoc find deletes.
Code Example
find /var/log -type f -size +50M -mtime +30 -print # verify first find /var/log -type f -size +50M -mtime +30 -delete
💡
Interview Tip
Say to dry-run with -print first, and that logrotate is the right long-term tool — ad-hoc deletes are for one-offs.
linuxfindcleanuplogs