如何在osx上实现linux的inotify-tools shell方法 [英] how to achieve linux's inotify-tools shell methods on osx

查看:149
本文介绍了如何在osx上实现linux的inotify-tools shell方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要监视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脚本中,则可以使用可在Linux和OSX上使用的Watchdog.

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}"' \
    .

To monitor a file in linux, I can use inotify-tools like this

#!/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

but how would I achieve this in OSX?

If you want to wrap this into a Python script, you can use Watchdog, which works with both Linux and OSX.

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

Here is what it looks like to replace pyinotify with watchdog:

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

Watchdog also has a shell utility called watchmedo:

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

这篇关于如何在osx上实现linux的inotify-tools shell方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆