繁体   English   中英

使用bash shell脚本检查linux上目录中的最新文件更新

[英]Check latest file updates in directory on linux using bash shell scripting

我有linux bash shell脚本的基本知识,现在我面临的问题如下:

  1. 假设我在一个空目录mydir中工作
  2. 然后有一个过程由C程序创建,用于生成一个单词的文件。 (Exp:file.txt会有一个单词,“你好”)
  3. 通常,在一段特定的时间之后,C程序用相同的单词“hello”更新文件。
  4. 我希望每次更新时检查文件。
  5. 但问题是我还希望我的脚本在检查文件更新时执行其他操作,当它检测到文件更新时,它会返回一些我可以用来触发其他内容的东西。

所以,任何人都可以帮助我。

还有一些概念证明:

while true;
do 
    func1();
    func2();
    check file is updated or not 
    if updated ; then
       break;
     else
      continue;

您可能需要stat命令。 请查看man stat以了解您的工作原理。 您想要查找“modtime”或“上次修改数据的时间”选项。 对于我的那个将是stat -c%Y file basemodtime=$(stat -c%Y file)循环,前modtime=$(stat -c%Y file)func2()然后if [ $modtime != $basemodtime ]; then if [ $modtime != $basemodtime ]; then检测“更新”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM