打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
shell 文件修改时间对比

https://blog.csdn.net/m0_37981386/article/details/112418966

#rm -f cpptime.time # #获取路径 currentPath=`pwd`'/test.cpp' #echo $currentPath #获取文件最后修改的时间戳 #time=`stat -c %Y $currentPath` #格式化 #formart_date=`date '+%Y-%m-%d %H:%M:%S' -d @$time` #echo $formart_date #把文件路径和时间写入文件 #echo "$currentPath"'|'"$time" > cpptime.time #验证文件 vertifyFile="cpptime.time" #不用编译的文件 equaltimefile='' #需要编译的文件 notequaltimefile='' #参数是要判断的一个文件路径 function JudgeChangeFile() { #判断验证文件是否存在且不为空 , -s表示不为空 if [ -e $vertifyFile ] && [ -s $vertifyFile ] #是否存在cpptine.time文件 then #echo "vertifyFile is exist!" `` # 放置一个空命令 else #echo "vertifyFile is not exist!" notequaltimefile=$notequaltimefile" "$@ return fi while read line do #echo $line #提取第一部分和第二部分, f1是第一部分,f2是第2部分 #echo $line|cut -d "|" -f1#文件路径 #echo $line|cut -d "|" -f2#文件的时间戳 #$@ 函数的所有参数$currentPath if [ $@ = `echo $line|cut -d "|" -f1` ] #cpp文件名字是否验证文件内的名字 then #在验证文件里面存在文件名字 #echo "vertify file exist cpp filename " #要判断的当前文件时间 time=`stat -c %Y $@` if [ $time = `echo $line|cut -d "|" -f2` ] #文件是否修改了 then #没有修改 #echo "equal time " equaltimefile=$equaltimefile" "$@ else #文件修改了 echo "not equal time" notequaltimefile=$notequaltimefile" "$@ fi return fi done < $vertifyFile #在验证文件里面不存在文件名 ,当作修改文件处理 echo "vertify file not exit cpp filename "$@" "`echo $line|cut -d "|" -f1` notequaltimefile=$notequaltimefile" "$@ } echo '-----------------------------' #函数调用 JudgeChangeFile $currentPath JudgeChangeFile `pwd`'/test2.cpp' echo "没有改动的文件:"$equaltimefile echo echo "修改的文件:"$notequaltimefile #删除修改时间验证文件,重新创建 if [ -e $vertifyFile ] #是否存在cpptine.time文件 then #echo "vertifyFile is exist! " rm -f $vertifyFile else #echo "vertifyFile is not exst,Create!" touch cpptime.time fi #echo "------WriteTimeFile-----------" #Write to cpptime.time function WriteTimeFile() { for filepathname in $@ do #echo $filepathname time=`stat -c %Y $filepathname` #把文件名称和文件的修改时间写到验证文件 echo "$filepathname"'|'"$time" >> cpptime.time done } #把cpp文件和文件修改时间都写到验证文件 WriteTimeFile $equaltimefile WriteTimeFile $notequaltimefile

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
批处理全盘搜索指定文件获取其完整路径
dos获取路径参数 的方法
Hadoop云盘系统
DOS命令:查找某路径下文件并批量复制
分享几个好用到爆的 Python 模块,建议收藏!
第35天:pathlib 模块
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服