1. 程式人生 > >批量創建並刪除日誌文件

批量創建並刪除日誌文件

nag mark 技術分享 比較 root tex -exec 文件 mar

按照下圖創建日誌文件:

技術分享圖片
使用腳本創建

for n in `seq 14`;
do
date -s "2016/03/$n";
touch access_www_$(date +%F).log;
done
~     

並刪除7天之前的文件:當然所有的就都刪除幹凈了:
三種方法都可以:

[root@centos heqiuyu]# find /root/heqiuyu -type f -mtime +7 | xargs rm -f
[root@centos heqiuyu]# find /root/heqiuyu -type f -mtime +7 -exec rm -f {} \;
[root@centos heqiuyu]# rm 
-f `find /root/heqiuyu -type f -mtime +7`

個人比較傾向於 用反引號這個

批量創建並刪除日誌文件