shell 文件修改时间
date +%s查看当前时间,以秒为单位。
stat -c %Y $file查看$file修改时间距今多少秒。
timestamp=`date +%s`
filetimestamp=`stat -c %Y $file`
timecha=$[$timestamp - $filetimestamp]
echo "timecha:${timecha}"
if [[ $timecha -gt 10 ]];then
echo "the file has been modified more than 10s"
fi
检查文件距今修改时间。
latest=""
latest_time=0
for file in ` ls $1 `
do
if [ ! -d $1"/"$file ];then
a=`stat -c %Y $1"/"$file`
if [ $latest_time -lt $a ];then
latest=$file
latest_time=$a
fi
fi
done
echo $latest
找出文件夹下最新文件。

浙公网安备 33010602011771号