【问题标题】:how to achieve linux's inotify-tools shell methods on osx如何在osx上实现linux的inotify-tools shell方法
【发布时间】:2011-10-21 06:17:45
【问题描述】:

要在 linux 中监控文件,我可以像这样使用 inotify-tools

#!/bin/bash

# with inotify-tools installed, watch for modification of file passed as first param
while inotifywait -e modify $1; do
        # do something here
done

但我如何在 OSX 中实现这一点?

【问题讨论】:

    标签: file macos watch inotify-tools


    【解决方案1】:

    您可以使用entr 工具。示例用法:

    ls some_file | entr do_something
    

    在 Mac 上通过 Brew 安装:brew install entr

    【讨论】:

      【解决方案2】:

      是的,您可以使用FSEvents API

      【讨论】:

      【解决方案3】:

      如果您想将其封装到 Python 脚本中,可以使用 Watchdog,它适用于 Linux 和 OSX。

      https://pypi.python.org/pypi/watchdog

      下面是用看门狗替换 pyinotify 的样子:

      https://github.com/raphdg/baboon/commit/2c115da63dac16d0fbdc9b45067d0ab0960143ed

      Watchdog 还有一个名为 watchmedo 的 shell 实用程序:

      watchmedo shell-command \
          --patterns="*.py;*.txt" \
          --recursive \
          --command='echo "${watch_src_path}"' \
          .
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-11-02
        • 1970-01-01
        • 2011-08-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-07
        相关资源
        最近更新 更多