7

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でこれをどのように達成できますか?

4

3 に答える 3

6

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}"' \
    .
于 2013-03-27T22:19:24.283 に答える
3

はい、FSEvents APIを使用できます

于 2011-08-05T22:55:02.913 に答える
1

ツールを使用できentrます。使用例:

ls some_file | entr do_something

Mac の場合、Brew: でインストールしますbrew install entr

于 2016-07-06T17:19:38.340 に答える