得到一个文件夹内的文件,如果超过7天并且不是本月的文件,则按照其修改日期创建文件夹并将文件移入文件夹,完成归档分类。
这是我写的一个Shell脚本,可以得到文件夹内七天前的文件,但包含当前文件夹的目录。
#!/bin/bash
#文件夹目录 多个以空格分隔
dir_array=(/root/logs /data/PVsor)
#天数
creation_time=7
for((i=0; i<${#dir_array[*]}; i++))
do
find .${dir_array[i]} -type f -mtime +"$creation_time" -name "*.*"
#date=`ls -l ${dir_array[i]} --time-style=full-iso|awk '{print $6,$7;}'|sed -e 's/\..*//' -e 's/[- :]//g'`
echo ${dir_array[i]}
#echo ${date}
echo the dir name is ${dir_array[i]}
done
本人shell是个初学的新手,求各位赐教,谢谢!