用shell脚本怎么取
我的文件是yyyyMMdd+2位序号的xml
例如:
/app/test/2015112001.xml
/app/test/2015112002.xml
/app/test/2015112401.xml
/app/test/2015112402.xml
/app/test/2015112403.xml
我需要取出最近7天的文件列表,或者是某几天的文件的列表
$ cat a.sh
#!/bin/sh
beg_date=date -d "$1" +%s
end_date=date -d "$2" +%s
if [[ -z $1 ]]||[[ -z $2 ]];then
echo "Usage: $0 YYYYMMDD YYYYMMDD"
exit 0;
fi
if [[ ${beg_date} > ${end_date} ]];then
echo "The end_date < beg_date ;Please input the right date,example: $0 20140101 20140301"
exit 0;
fi
for (( i=${beg_date};i<=${end_date};i=i+86400))
do
ls date -d @${i} +%Y%m%d
done
find app/test/ -name "[0-9]{8,8}.xml" -type f -mtime -7 -print