[英]How to delete some file with crontab in linux
I have two questions about using crontab file: 关于使用crontab文件,我有两个问题:
1.I am using a service. 1.我正在使用一项服务。 When it runs, a new log file created everyday in a log directory.
运行时,每天都会在日志目录中创建一个新的日志文件。 i want to delete all files that already exist greater 5 day in that log directory
我想删除该日志目录中已有5天以上的所有文件
2.I want to delete all the infomation that exist greater than 5 days in a log file( /var/log/syslog) 2.我要删除日志文件(/ var / log / syslog)中存在超过5天的所有信息
I don't know how to do that with crontab in linux. 我不知道如何在Linux中使用crontab做到这一点。 Please help me!
请帮我! Thanks in advance!
提前致谢!
find /path/to/log/folder -mtime +5 -type f -exec rm {} \\;
找到/ path / to / log / folder -mtime +5 -type f -exec rm {} \\;
Or more specific match a pattern in the filename 或者更具体地匹配文件名中的模式
find .
找 。 -mtime +5 -type f -name *.log -exec ls -l {} \\;
-mtime +5 -type f -name * .log -exec ls -l {} \\;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.