gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 11:29:32 26 4
gpt4 key购买 nike

要在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com