Quick Linux Tip #02: How do I clean up old log files automatically?

Quick Linux Tip #2:

Try: sudo find /var/log -name '*.log' -mtime +30 -delete

Info: Delete log files older than 30 days. The -mtime +30 finds files modified more than 30 days ago. Use sudo because /var/log files are owned by root.

Examples:

  • $ sudo find /var/log -name '*.log' -mtime +30 -delete
  • $ find ~/Downloads -type f -size +1G -delete
  • $ find /tmp -name '*.tmp' -mtime +7 -delete

Note: Use sudo for system directories. Use -ls first to preview what will be deleted. Deletion is permanent.




LinuxTeck.com
linuxteck@ubuntu:~$ sudo find /var/log -name '*.log' -mtime +30 -delete

linuxteck@ubuntu:~$

About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.

L