file - 如何在 osx 上实现 linux 的 inotify-tools shell 方法

标签 file macos watch inotify-tools

要在 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 中实现这一目标?

最佳答案

如果您想将其封装到 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}"' \
    .

关于file - 如何在 osx 上实现 linux 的 inotify-tools shell 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6963423/

相关文章:

java - 如何将文件/目录移动到 Java 中的回收站而不是永久删除它

perl - 如何在 Perl 中更改、删除或插入文件中的一行,或附加到文件的开头?

java - 无法删除文件 Java

Android 4.3 作为低功耗蓝牙外设

javascript - grunt-watch 跳过了我的一些任务,为什么?

python - 如何在 Python 2.7 中从文件中读取字典?

python - 什么是 os.fdopen() 语义?

linux - 使用 watch 每 N 秒更新一次在 linux 中显示的图像失败

javascript - Angularjs 深度 $watch 不工作

python - 在 OS X 中创建包安装程序——安装 Python、NumPy 和其他依赖项