【问题标题】:Delete log file in LINUX [closed]删除 LINUX 中的日志文件 [关闭]
【发布时间】:2021-02-01 20:41:24
【问题描述】:

我的 tomcat 文件夹中有几个日志文件 - /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

我运行命令 find /var/lib/tomcat9/logs/ -type f -mtime +2 -exec rm {} ;

它会删除所有文件,包括catalina文件和localhost文件。

我可以知道如何在 2 天内删除文件,但不包括 catalina 和 localhost 文件。

谢谢。

【问题讨论】:

  • 鉴于您的列表,将-name "rest*" 添加到您的find 命令应该可以。
  • 你也可以使用:find /var/lib/tomcat9/logs/ -type f -mtime +2 ! \( -name localhost* -o -name catalina* \) -exec rm {} \;

标签: linux delete-file tomcat9


【解决方案1】:
find /var/lib/tomcat9/logs/ -type f -name "restful*" -mtime +10 -exec rm {} \;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-07
    • 2022-01-23
    • 1970-01-01
    • 2012-10-02
    • 1970-01-01
    • 2020-11-12
    • 1970-01-01
    相关资源
    最近更新 更多