gpt4 book ai didi

macos - Mac上有类似 "watch"或 "inotifywait"这样的命令吗?

转载 作者:行者123 更新时间:2023-12-02 01:15:07 30 4
gpt4 key购买 nike

我想监视 Mac 上的文件夹,然后执行 bash 脚本,向其传递刚刚移入或在监视目录中创建的任何文件/文件夹的名称。

最佳答案

fswatch

fswatch是一个使用 Mac OS X FSEvents API 来监视目录的小程序。当收到有关对该目录进行任何更改的事件时,指定的shell命令由/bin/bash

执行

如果您使用的是 GNU/Linux, inotifywatch (的一部分大多数发行版上的 inotify-tools 包)提供了类似的功能。

更新: fswatch 现在可以在许多平台上使用,包括 BSD、Debian 和 Windows。

语法/简单示例

可以观察多个路径的新方式 - 对于版本 1.x 及更高版本:

fswatch -o ~/path/to/watch | xargs -n1 -I{} ~/script/to/run/when/files/change.sh

Note: The number output by -o will get added to the end of the xargs command if not for the -I{}. If you do choose to use that number, place {} anywhere in your command.

版本 0.x 的旧方法:

fswatch ~/path/to/watch ~/script/to/run/when/files/change.sh

使用 Homebrew 安装

截至 2013 年 9 月 12 日,它已添加回 homebrew - 耶!因此,更新您的公式列表(brew update),然后您需要做的就是:

brew install fswatch

不使用 Homebrew 安装

Terminal.app中键入这些命令

cd /tmp
git clone https://github.com/alandipert/fswatch
cd fswatch/
make
cp fswatch /usr/local/bin/fswatch

如果您的系统上没有 c 编译器,您可能需要安装 Xcode 或 Xcode 命令行工具 - 两者都是免费的。但是,如果是这种情况,您可能应该只是 check out homebrew .

fswatch 版本 1.x 的其他选项

Usage:
fswatch [OPTION] ... path ...

Options:
-0, --print0 Use the ASCII NUL character (0) as line separator.
-1, --one-event Exit fsw after the first set of events is received.
-e, --exclude=REGEX Exclude paths matching REGEX.
-E, --extended Use exended regular expressions.
-f, --format-time Print the event time using the specified format.
-h, --help Show this message.
-i, --insensitive Use case insensitive regular expressions.
-k, --kqueue Use the kqueue monitor.
-l, --latency=DOUBLE Set the latency.
-L, --follow-links Follow symbolic links.
-n, --numeric Print a numeric event mask.
-o, --one-per-batch Print a single message with the number of change events.
in the current batch.
-p, --poll Use the poll monitor.
-r, --recursive Recurse subdirectories.
-t, --timestamp Print the event timestamp.
-u, --utc-time Print the event time as UTC time.
-v, --verbose Print verbose output.
-x, --event-flags Print the event flags.

See the man page for more information.

关于macos - Mac上有类似 "watch"或 "inotifywait"这样的命令吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1515730/

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