现在的位置: 首页 > 综合 > 正文

删除指定目录下的过期文件

2012年10月16日 ⁄ 综合 ⁄ 共 642字 ⁄ 字号 评论关闭

测试时,需要自动删除录制的文件,于是写了个脚本,自动删除过期的文件。

 

如下:

 1 #!/bin/bash
2 #待删除目录,根路径
3 root_path="/figure/Record"
4
5 #保存时间:分钟
6 save_time=1
7
8 for source_type in $(ls ${root_path})
9 do
10 if test -d ${root_path}/${source_type};then #录制对象目录
11 cd ${root_path}/${source_type}
12
13 for channels in $(ls -b ${root_path}/${source_type}) #通道目录
14 do
15 if test -d ${channels};then
16 cd ${channels}
17
18 for dates in $(ls ${root_path}/${source_type}/${channels}) #日期目录
19 do
20 if test -d ${dates};then
21 cd ${root_path}/${source_type}/${channels}/${dates}
22 find ${root_path}/${source_type}/${channels}/${dates} -type f -mmin ${save_time} -exec rm -fv '{}' \;
23 fi
24 done
25 fi
26 done
27 else
28 echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
29 fi
30 done

 

 

抱歉!评论已关闭.