我想在我的Mac上监视一个文件夹,然后执行一个bash脚本,将刚刚移动到或在监视目录中创建的任何文件/文件夹的名称传递给它。
当前回答
下面是使用sschober工具的一行代码。
$ while true; do kqwait ./file-to-watch.js; script-to-execute.sh; done
其他回答
Sudo fs_usage -f filesys | grep“有趣的事情”?
看门狗是一个跨平台的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如何工作的示例。
您可能想看一看(或者扩展一下)我的小工具kqwait。目前它只是坐在那里等待单个文件上的写事件,但是kqueue架构允许分层事件堆叠…
Facebook的看门人(watchman)在Homebrew上也很好用。它还支持过滤:
这两行代码在源目录上建立一个监视,然后进行设置 在名为buildme的触发器上运行一个名为miniify -css的工具 每当CSS文件被更改时。工具将被传递一个列表 改变文件名。 $ watchman watch ~/src $ watchman—trigger ~/src buildme '*.css'—mini -css
注意,路径必须是绝对的。
推荐文章
- 在Mac OS X上哪里安装Android SDK ?
- Mac/OS X上的/var/lib/docker在哪里
- Xcode构建失败“架构x86_64未定义的符号”
- 在OSX 10.11中安装Scrapy时,“OSError: [Errno 1]操作不允许”(El Capitan)(系统完整性保护)
- 如何在Mac OS X 10.6中使硬件发出哔哔声
- 从Cocoa应用程序执行一个终端命令
- Android Studio无法找到有效的Jvm(与MAC OS相关)
- NSRange从Swift Range?
- 如何在交互式Python中查看整个命令历史?
- 在OSX中永久设置PATH环境变量
- 如何停止mysqld
- 如何从远程SSH会话发送数据到本地剪贴板
- SSH端口转发~/。ssh /配置文件?
- 如何复制文件跨计算机使用SSH和MAC OS X终端
- Mac SQLite编辑器