小编Shy*_*Shy的帖子

如何使用 inotifywait 监视目录以创建特定扩展名的文件

我看过这个答案

您应该考虑使用 inotifywait,例如:

inotifywait -m /path -e create -e moved_to |
    while read path action file; do
        echo "The file '$file' appeared in directory '$path' via '$action'"
        # do something with the file
    done
Run Code Online (Sandbox Code Playgroud)

我的问题是,上面的脚本监视目录以创建任何类型的文件,但是如何修改inotifywait命令以仅在创建特定类型/扩展名的文件(或移动到目录中)时报告 - 例如它应该.xml创建任何文件时报告。

我试过的:

我已经运行了inotifywait --help命令,并阅读了命令行选项。它具有--exclude <pattern>--excludei <pattern>命令来排除某些类型的文件(通过使用正则表达式),但我需要一种方法来只包括某些类型/扩展名的文件。

shell filesystems monitoring shell-script inotify

35
推荐指数
5
解决办法
9万
查看次数

标签 统计

filesystems ×1

inotify ×1

monitoring ×1

shell ×1

shell-script ×1