Inotify

inotify 不在一個特定文件夾上工作

  • August 16, 2016

我有一個問題,無論我做什麼,inotify 都不會檢測到某個特定文件夾中的更改。它檢測其他文件夾中的更改,否則沒有什麼不同。這可能是什麼原因造成的?

inotifywait 3.14
Linux titan 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2+deb8u3 (2016-07-02) x86_64 GNU/Linux

inotify 在這裡按預期工作:

在一個終端中:

ben@titan:~$ mkdir -p notifytest/example
ben@titan:~$ cd notifytest
ben@titan:~/notifytest$ inotifywait -rme attrib,modify,move,create,delete . --exclude '(log|[a-z]+.sqlite)'

在另一個終端:

ben@titan:~$ cd notifytest
ben@titan:~/notifytest$ touch test.txt
ben@titan:~/notifytest$ touch example/test.txt
ben@titan:~/notifytest$ rm example/test.txt
ben@titan:~/notifytest$ rm test.txt

輸出:

Setting up watches.  Beware: since -r was given, this may take a while!
Watches established.
./ CREATE test.txt
./ ATTRIB test.txt
./example/ CREATE test.txt
./example/ ATTRIB test.txt
./example/ DELETE test.txt
./ DELETE test.txt

inotify 在這裡無法按預期工作:

我有一個名為的現有文件夾blog被忽略:(

我創建了一個名為example正確觀看的新文件夾

在一個終端中:

ben@titan:~$ cd some-path
ben@titan:~/some-path$ ls
drwxr-xr-x 3 ben     ben      4096 Aug 16 14:23 blog
-rw-r--r-- 1 ben     ben     17408 Aug 15 13:58 blog.sqlite
-rw-r--r-- 1 ben     ben       325 Aug 15 13:01 config.py
-rw-r--r-- 1 www-run www-run 91800 Aug 16 14:23 log
drwxr-xr-x 2 ben     ben      4096 Aug 15 14:14 public_html
-rw-r--r-- 1 ben     ben      1999 Aug 15 16:21 schema.sql
-rwxr-xr-x 1 ben     ben      6019 Aug 16 14:01 start.py
ben@titan:~/some-path$ mkdir example
ben@titan:~/some-path$ ls
drwxr-xr-x 3 ben     ben      4096 Aug 16 14:23 blog
-rw-r--r-- 1 ben     ben     17408 Aug 15 13:58 blog.sqlite
-rw-r--r-- 1 ben     ben       325 Aug 15 13:01 config.py
drwxr-xr-x 2 ben     ben      4096 Aug 16 14:28 example
-rw-r--r-- 1 www-run www-run 91800 Aug 16 14:23 log
drwxr-xr-x 2 ben     ben      4096 Aug 15 14:14 public_html
-rw-r--r-- 1 ben     ben      1999 Aug 15 16:21 schema.sql
-rwxr-xr-x 1 ben     ben      6019 Aug 16 14:01 start.py
ben@titan:~/some-path$ file example
example: directory
ben@titan:~/some-path$ file blog
blog: directory
ben@titan:~/some-path$ inotifywait -rme attrib,modify,move,create,delete . --exclude '(log|[a-z]+.sqlite)'

在另一個終端:

ben@titan:~$ cd some-path
ben@titan:~/some-path$ touch test.txt
ben@titan:~/some-path$ touch blog/test.txt
ben@titan:~/some-path$ touch example/test.txt
ben@titan:~/some-path$ rm test.txt
ben@titan:~/some-path$ rm blog/test.txt 
ben@titan:~/some-path$ rm example/test.txt 

輸出:

inotifywait -rme attrib,modify,move,create,delete . --exclude '(log|[a-z]+.sqlite)'
Setting up watches.  Beware: since -r was given, this may take a while!
Watches established.
./ CREATE test.txt
./ ATTRIB test.txt
./example/ CREATE test.txt
./example/ ATTRIB test.txt
./ DELETE test.txt
./example/ DELETE test.txt

預期輸出:

inotifywait -rme attrib,modify,move,create,delete . --exclude '(log|[a-z]+.sqlite)'
Setting up watches.  Beware: since -r was given, this may take a while!
Watches established.
./ CREATE test.txt
./ ATTRIB test.txt
./example/ CREATE test.txt
./example/ ATTRIB test.txt
./blog/ CREATE test.txt
./blog/ ATTRIB test.txt
./ DELETE test.txt
./example/ DELETE test.txt
./blog/ DELETE test.txt

你的--exclude (log)模式匹配b**log**

改為使用^log$

引用自:https://unix.stackexchange.com/questions/303723