我想在我的Mac上监视一个文件夹,然后执行一个bash脚本,将刚刚移动到或在监视目录中创建的任何文件/文件夹的名称传递给它。
当前回答
我的fswatch的分支提供了inotifywait -m的功能,稍微少一点(没有等待,更多!)我在Linux上使用inotifywait…)解析友好的输出有很多问题。
它是对原始fswatch的改进,因为它通过STDOUT发送更改后的文件的实际路径,而不是要求您提供它所派生的程序。
它是我用来实现自动化的一系列可怕的bash脚本的坚实基础。
(这是跑题了)Linux上的inotifywait,另一方面,需要大量的拼凑,我仍然没有找到一个好方法来管理它,尽管我认为基于node.js的东西可能是票据。
其他回答
这里只是提到,当文件发生变化时,entr可以作为OSX上运行任意命令的替代选项。我发现它既简单又有用。
在macos上酿造安装入口 在Debian/Ubuntu上安装entr
看门狗是一个跨平台的python API,用于监视文件/目录,它有内置的“诡计”工具,允许您在事件发生时触发动作(包括shell命令)(包括新添加的文件,删除的文件和更改的文件)。
编辑:fsw已合并到fswatch。在这个答案中,任何对fsw的引用现在都应该读为fswatch。
我在c++中写了一个fswatch的替代品,叫做fsw,它有几个改进:
It's a GNU Build System project which builds on any supported platform (OS X v. >= 10.6) with ./configure && make && sudo make install Multiple paths can be passed as different arguments: fsw file-0 ... file-n It dumps a detailed record with all the event information such as: Sat Feb 15 00:53:45 2014 - /path/to/file:inodeMetaMod modified isFile Its output is easy to parse so that fsw output can be piped to another process. Latency can be customised with -l, --latency. Numeric event flags can be written instead of textual ones with -n, --numeric. The time format can be customised using strftime format strings with -t, --time-format. The time can be the local time of the machine (by default) or UTC time with -u, --utc-time.
焊:
fsw托管在GitHub上,可以克隆它的存储库:
git clone https://github.com/emcrisostomo/fsw
安装的焊:
FSW可以通过以下命令安装:
./configure && make && sudo make install
进一步的信息:
我还写了一篇介绍性的博客文章,您可以在其中找到几个关于fsw如何工作的示例。
福斯沃琪
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
注意:如果没有-I{}, -o输出的数字将被添加到xargs命令的末尾。如果您选择使用该数字,请将{}放置在命令中的任何位置。
版本0.x的旧方法:
fswatch ~/path/to/watch ~/script/to/run/when/files/change.sh
使用Homebrew安装
13年9月12日,它又被添加到自制啤酒中——耶!所以,更新你的公式列表(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命令行工具——都是免费的。然而,如果是这样的话,你可能应该试试自制啤酒。
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.
Apple OSX文件夹操作允许您根据对文件夹采取的操作自动化任务。
推荐文章
- 警告用户/local/mysql/data目录不属于mysql用户
- 在Mac OS X上使用鼠标聚焦(加上自动提升)
- 我在哪里可以找到Mac OS X Lion的“make”程序?
- 当我没有Mac的时候,在Mac/Safari上测试web应用程序
- Angular中相当于AngularJS $watch的东西是什么?
- 在Mac上安装MySQL后,使用ALTER USER语句重置MySQL root密码
- my.cnf文件在macOS上的位置
- 如何从Mac OS X上卸载MySQL ?
- 查找当前可执行文件的路径,不包含/proc/self/exe
- 在Mac上安装R -警告消息:设置LC_CTYPE失败,使用“C”
- 为什么cURL返回错误“(23)Failed writing body”?
- 节点和错误:EMFILE,打开的文件太多
- 如何使用命令行工具为Mac OS X创建一个漂亮的DMG ?
- 由于环境错误无法安装包:[Errno 13]
- Mac压缩没有__MACOSX文件夹?