【问题标题】:How to check when a file has been changed in linux?如何在linux中检查文件何时更改?
【发布时间】:2014-03-12 09:15:49
【问题描述】:

我有一个 Linux 命令行程序。

它产生一个文件的输出。

程序在很短的时间间隔后不断修改输出文件。

每次程序更改文件时,我都希望得到通知。

是否有任何命令行或任何可以帮助我的脚本?

【问题讨论】:

标签: linux file events command-line


【解决方案1】:

我认为icrond 是你所需要的

incrond(inotify cron 守护程序)是一个守护程序,它监视文件系统事件(例如添加新文件、删除文件等)并执行命令或 shell 脚本。用法一般类似于cron

在这里查看一些示例http://www.cyberciti.biz/faq/linux-inotify-examples-to-replicate-directories/

【讨论】:

    【解决方案2】:

    我认为你需要

    Linux:inotify

    File Alteration monitor

    incron

    Linux audit

    也请看here

    对于脚本,您可能需要如下使用 inotify 工具。

    while true; do
      change=$(inotifywait -e close_write,moved_to,create .)
      change=${change#./ * }
      if [ "$change" = "myfile" ]
      then 
          echo -e "my file changed"
        fi
    done
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-08
      • 1970-01-01
      • 2011-06-09
      • 1970-01-01
      • 2015-09-05
      相关资源
      最近更新 更多