小编six*_*x-k的帖子

如何使用inotifywait查看文件夹而不是文件夹中的文件

我想使用 inotifyway 来监视文件夹中新创建或移动的文件,但仅限于文件。

假设我的文件夹名为“watched_folder_test”,我的文件名为“toto.txt”。如果我使用 mv 命令将文件移动到 watched_folder_test 我得到通知我想要

假设在 watched_folder_test 中,我有一个名为 foo 的文件夹,我创建了一个名为“bar.txt”的文件。我收到了我想要的通知。

但这是我的问题。如果我在 watch_folder_test 之外有一个文件夹名称 foo 并且我在其中有一个文件名 bar.txt ( foo/bar.txt ) 并且我将整个文件夹移动到 watch_folder_test 中。我只收到 foo 已创建的通知!没有关于 bar.txt 的内容。但是,我并不真正关心 foo,我只想知道“bar.txt”

到目前为止,这是我的代码

#!/bin/bash                                                                                          

inotifywait -mr /home/romain/depot/watched_folder_test -e create -e moved_to |
    while read path action file; do
        echo "The file '$file' appeared in directory '$path' via '$action'"
        for ac in $action
        do
            isdir=`echo $ac | grep 'ISDIR'`
            if [ $? == 0 ]
            then
                echo "It's a folder"
            else
                echo "It's …
Run Code Online (Sandbox Code Playgroud)

bash ubuntu monitoring inotify inotifywait

3
推荐指数
1
解决办法
3405
查看次数

标签 统计

bash ×1

inotify ×1

inotifywait ×1

monitoring ×1

ubuntu ×1