linux 删除过期文件

写完备份后发现,数据需要定时删除;第一想法遍历文件,判断文件名,比对当前时间进行删除;然而这当然也是可以的;却又更加简便的方法;

find /mnt/sqlBac/ -type f -mtime +15 -exec rm -f '{} ;'

find /mnt/sqlBac/ -type f -mtime +15 -exec rm -f {} ;

find /mnt/sqlBac/ -type f -mtime +15 -exec rm -f {};

centos 6.5 下 使用第二条命令可用;

find 查找;

/mnt/sqlBac 文件存在目录;

-type f 文件类型为 普通文件;

mtime make file 的时间; 

-exec 执行命令;

rm -f 移除文件;

积累知识,分享知识,学习知识。
原文地址:https://www.cnblogs.com/bin-pureLife/p/4663434.html