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 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步