Delete log file in LINUX

326 Views Asked by At

I have several log file in my tomcat folder - /var/lib/tomcat9/logs

drwxrwxr-x 11 root   syslog 4096 Oct 01 06:25 ../
-rw-r-----  1 tomcat tomcat 5077 Oct 01 11:54 catalina.2020-10-01.log
-rw-r-----  1 tomcat tomcat    0 Oct 01 11:54 localhost.2020-10-01.log
-rw-r-----  1 tomcat tomcat  115 Oct 01 11:57 localhost_access_log..2020-10-01.txt
-rw-r-----  1 root   root   1716 Oct 01 11:57 restful.2020-10-01.log
-rw-r-----  1 root   root   1716 Oct 02 11:57 restful.2020-10-02.log
-rw-r-----  1 root   root   1716 Oct 03 11:57 restful.2020-10-03.log
-rw-r-----  1 tomcat tomcat 1716 Oct 19 11:57 restful.log

I run the command find /var/lib/tomcat9/logs/ -type f -mtime +2 -exec rm {} ;

It delete all the file including the catalina file and localhost file.

May I know how to delete file not later than 2 days but not incuding catalina and localhost file.

Thank you.

1

There are 1 best solutions below

0
On
find /var/lib/tomcat9/logs/ -type f -name "restful*" -mtime +10 -exec rm {} \;