我可以知道如何将命令输出中的日期与日期命令进行比较。我不知道该如何比较它们。基本上,我希望比较命令输出日期/时间和当前日期/时间,以检查它们之间的间隔时间。例如:
命令输出日期/时间=3月6日:37 当前日期/时间=3月6日:38
因此,间隔时间= 00:01,即1分钟。如果有人能帮我做这件事,我很感激。
ls -lrt | tail -1
date发布于 2019-03-06 06:47:49
从中世纪开始就有时间了。
startdate=$(ls -lrt --time-style=+"%s" | tail -1 | awk '{ print $6; }')
enddate=$(date +"%s")
echo "Start date $startdate"
echo "End date $enddate"
difference=$(expr $enddate - $startdate)
echo "Seconds difference $difference"
seconds=$((difference%60))
minutes=$((difference/60%60))
hours=$((difference/60/60%24))
days=$((difference/60/60/24))
printf '%02d:' $days
printf '%02d:' $hours
printf '%02d:' $minutes
printf '%02d\n' $seconds发布于 2019-03-06 06:41:11
echo "rame" > somefile #some dile
lastModified="$(stat -c %Y somefile)" #last modification date as seconds since Epoch
now=$(date +%s) #now time
d=$(($now-$lastModified)) #difference in seconds
echo $dhttps://stackoverflow.com/questions/55016636
复制相似问题