3

I have noticed that "logs" and "tmp" content take 36GB and 21GB respectively. I need to free up some disk space and currently wondering is it vise to clean them.

Thanks!

4

Delete logs older than 7 days.

find tomcat/logs/ -mtime +7 -print0 | xargs -r -0 rm -rf

You probably want to add this as a cronjob too.

Before deleting temp-files, you should make sure that nothing is holding them open.

1
  • find ... -execdir rm {} + is cleaner, and find ... -delete even more so, if they are available. – Tim Sylvester Oct 1 '18 at 19:10
1

You should set up tomcat in logrotate properly. Something like this as /etc/logrotate.d/tomcat:

/var/log/tomcat/*.log /var/log/tomcat/*.out {  
 copytruncate  
 daily  
 rotate 7  
 compress  
 missingok
}

tmp you might want to sweep using the find command that pkhamre showed, but I would use logrotate on the log files. You didn't say which distro you're using, but RHEL/CentOS has tmpwatch, which will remove files that haven't been accessed for a defined period of time.

1
  • If the filenames already have dates/times in them logrotate will consider each one a separate log and not do what you want. – Tim Sylvester Oct 1 '18 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.