我需要一个 linux bash 脚本来知道特定文件夹被修改的时间(以秒为单位)。 有人可以帮帮我吗?
我下面的当前脚本正在获取当前时间戳和上次修改文件夹的时间,但我不知道如何继续。
[root@cgf01 log]# more CheckLastCdr.sh
#get current timestamp
current_time=`date`
#get last CDR timestamp
last_cdr_time=`find /tmp/log/ -exec stat \{} --printf="%y\n" \; | sort -n -r | head -1`
echo $current_time
echo $last_cdr_time
当我运行这个脚本时,我得到以下信息:
[root@cgf01 log]# ./CheckLastCdr.sh
./CheckLastCdr.sh: line 6: 2011-04-05: command not found
Tue Apr 5 16:19:31 CEST 2011
2011-04-05 16:14:33.000000000 +0200
提前致谢
最佳答案
如果你想要之前的秒数:
echo $[$(date +%s)-$(stat --printf "%Y" /tmp/log)]
关于Linux 脚本以秒为单位获取上次修改文件夹的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5553420/