find 常用命令总结

1、删除3个月前的日志文件

find .  -type f  -name *.log  -mtime +180  -exec rm {} \;

2、查看3个月前的日志文件

find . -type f -mtime +90 -exec ls -l {} \; | more

3、移动三个月前的文件

find . -mtime +180 -type f -name "*.txt"  -exec mv  {} /tmp  \;

4、具体案例 

#!/bin/bash
#move 180 days ago apiReportStatus data
#version v1

LOCAL_DIR_M=/opt/apiReportStatus/
LOCAL_DIR_B=/tmp/apiReportStatus/

for i in `cat /opt/apiReportStatus_dir`
do

    cd ${LOCAL_DIR_M}/$i/  && find . -mtime +180 -type f -name "*.txt"  -exec mv  {} ${LOCAL_DIR_B}/$i/ \;

done

 

posted @ 2022-04-21 11:44  AlexMa  阅读(52)  评论(0)    收藏  举报