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

找出文件夹下最新文件。

本文作者:xzh-personal-issue

本文链接:https://www.cnblogs.com/xzh-personal-issue/p/17075923.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   心比天高xzh  阅读(332)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起