- linux 删除指定日期之前的文件
参考:https://www.cnblogs.com/tianruixue/p/5845070.html
1. 使用find命令
find /lxdir/xx -mtime +92 -type f -name *.test[12] -exec rm -rf {} \;
参数说明
/lxdir/xx --设置要操作的目录;
-mtime +92 --设置时间为91天前;
-type f --设置查找的类型为文件;
-name *.test[12] --设置文件名称中包含test1或者test2;
-exec rm -rf --查找完毕后执行删除操作;
2. 使用find命令结合xargs
find /lxdir/xx -ctime +92 -type f -name *.test[12] | xargs rm -rf
3. 如果需要定时操作,可以将命令直接加入crontab中,或将命令写到脚本里,将脚本加入crontab进行定时执行。通过下边的命令进行crontab任务的添加。
vi /etc/crontab