File 如何实现linux';在osx上使用inotify工具外壳方法

File 如何实现linux';在osx上使用inotify工具外壳方法,file,macos,watch,inotify-tools,File,Macos,Watch,Inotify Tools,要在linux中监视文件,我可以使用像这样的inotify工具 #!/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脚本中,您可以使用Wa

要在linux中监视文件,我可以使用像这样的inotify工具

#!/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一起工作

以下是用watchdog替换pyinotify的情况:

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

watchmedo shell-command \
    --patterns="*.py;*.txt" \
    --recursive \
    --command='echo "${watch_src_path}"' \
    .
你可以使用这个工具。用法示例:

ls some_file | entr do_something

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

这可以在shell脚本中使用吗?不可以,但有一个python包装库: