首页 > 系统相关 >shell 文件修改时间

shell 文件修改时间

时间:2023-01-30 14:55:54浏览次数:36  
标签:文件 stat shell echo 修改 timecha file fi latest

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

找出文件夹下最新文件。

标签:文件,stat,shell,echo,修改,timecha,file,fi,latest
From: https://www.cnblogs.com/xzh-personal-issue/p/17075923.html

相关文章