linux 脚本小示例

一、模拟删除7天前的日志文件

创建14天的虚拟文件

[root@localhost logs]# for n in `seq 14`;
> do
> date -s "2018/08/$n";
> touch access_www_$(date +%F).log
> done

[root@localhost logs]# date -s '2018/08/14'    #设置系统时间

[root@localhost logs]# find /app/logs -type f -mtime +7    #查看7天前被修改过的文件

方法1:[root@localhost logs]# find /app/logs -type f -mtime -7 -exec rm -f {} \;

方法2:[root@localhost logs]# rm -f `find /app/logs/ -type f -mtime +7` 

方法3:[root@localhost logs]# find /app/logs -type f -mtime +7|xargs rm -f

猜你喜欢

转载自blog.csdn.net/weixin_42125267/article/details/81635579