使用cron作业删除日志文件 [英] Remove log files using cron job
问题描述
嗨.我想从文件夹中删除最近7天的所有日志文件,但保留所有其他文件.我可以使用以下命令吗?您如何指定它只删除扩展名为.log的文件?
Hi. I want to remove all log files from the last 7 days from a folder, but leave all the other files. Can I use the below command? How do you specify that it just delete the files with .log extension?
find /path/to/file -mtime +7 -exec rm -f {} \;
我是否需要将此命令写入某个文件,还是可以仅在命令提示符下将其写入并每天自动运行?
Do I need to write this command into some file, or can I just write it in command prompt and have it run automatically every day?
我不知道如何在linux中运行cron作业.
I have no idea how to run a cron job in linux.
推荐答案
使用通配符.只需将其放入您的crontab
中,即可使用 crontab -e 选项编辑您的crontab作业.
查看示例:
Use wildcard . And just put it in your crontab
use the crontab -e option to edit your crontab jobs.
See example :
* * * * * find /path/to/*.log -mtime +7 -exec rm -f {} \;
只是增加答案,请查看这篇有关如何使用您的计算机的不错的文章crontab
!在Linux中.
Just to increment the answer check this nice article on how to work with your crontab
! in Linux .
将corntab更新为crontab
update corntab to crontab
这篇关于使用cron作业删除日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!