shell脚本之基于时间的文件筛选

#!/bin/bash
#输入筛选文档的起始日期和截止日期
read
-p "input firsttime,like 2018-5-6 2:20:31:" first_time
read
-p "input secondtime,like 2019-5-6 2:31:5:" second_time #read -p "input the path of save:"savepath echo $first_time echo $second_time if [ -f file.txt ] then touch file.txt fi
#将格式化的日期转成时间戳,方便比较
first_time=`date -d "$first_time" +%s` second_time=`date -d "$second_time" +%s`
#使用递归函数遍历文件目录,筛选出该目录下的所有符合条件的文档
function document(){ for file in `ls $1` do echo $1"/"$file if [ -d $1"/"$file ] then echo $1"/"$file is a document document $1"/"$file else aim_time=`ls -lt --full-time $1"/"$file | awk '{ print $6,$7 }'` aim_time=`date -d "$aim_time" +%s` if [ "$first_time" -lt "$aim_time" ] && [ "$aim_time" -lt "$second_time" ] then echo $1“/”$file>>file.txt fi fi done }
#递归函数的参数是需要筛选的目标目录
document $
1

 

posted @ 2019-07-04 09:40  石桥浪子  阅读(1107)  评论(0编辑  收藏  举报