Skip to main content

~/discoveries

[snippet]

Delete logs older than 7 days with find

find + -mtime + -delete is safer than a recursive rm when you scope the path.

find /var/log/myapp -type f -name "*.log" -mtime +7 -print
# review the list, then:
find /var/log/myapp -type f -name "*.log" -mtime +7 -delete

Always -print first. -delete only after you’ve confirmed the match set.