我看过这个答案。
您应该考虑使用 inotifywait,例如:
Run Code Online (Sandbox Code Playgroud)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
我的问题是,上面的脚本监视目录以创建任何类型的文件,但是如何修改inotifywait命令以仅在创建特定类型/扩展名的文件(或移动到目录中)时报告 - 例如它应该.xml创建任何文件时报告。
我试过的:
我已经运行了inotifywait --help命令,并阅读了命令行选项。它具有--exclude <pattern>和--excludei <pattern>命令来排除某些类型的文件(通过使用正则表达式),但我需要一种方法来只包括某些类型/扩展名的文件。