0

我在inotifywait文件目录上运行:

inotifywait --quiet --monitor  \
  --event modify \
  --event moved_to \
  --event moved_from \
  --event move \
  --event unmount \
  --event create \
  --format '%w' /path/to/*.json | \
while read FILE; do
  echo "$FILE was changed."
done

这在我运行之前运行良好git checkout [some existing branch name]。之后,inotifywait停止响应git签出分支时更新的文件(即停止响应两个分支之间不同的文件)。

为什么inotifywait停止响应这些文件?有没有办法让它重新查看这些文件?

4

1 回答 1

2

inotifywait --event create /path/to/*.json根本不起作用,因为一个已经存在的文件不能有一个create事件,并且在启动/path/to/*.json之前被你的shell替换为一个已经存在的文件名列表inotifywait;任何不存在的文件都不会被包含在内,当inotifywait open()s 是现有文件时,它只会获得预先存在的副本,因此将来甚至不会看到任何以相同名称创建的新文件。

而是按照目录:

inotifywait --quiet --monitor  \
  --event modify \
  --event moved_to \
  --event moved_from \
  --event move \
  --event unmount \
  --event create \
  --format '%w' /path/to | \
while IFS= read -r file; do
  [[ $file = *.json ]] || continue  # ignore any non-*.json files
  echo "$file was changed."
done

于 2020-01-29T16:13:55.657 回答