我如何在Linux中创建一个文件监听器? [英] How do I create a file listener in linux?
问题描述
我想创建揭开序幕Linux命令当文件在这个路径就显示了一个特定目录的监听器。例如,每当一个文件显示在如C目录:/家/我想从文件中读取文本字符串,然后揭开序幕另一个命令。我想用一个循环,但似乎效率不高。
I am trying to create a listener on a specific directory that kicks off a Linux command whenever a file shows up in this path. For example, whenever a file shows up in a directory like C:/home/ I would like to read a string of text from that file and then kick off another command. I was thinking of using a loop but that seems inefficient.
推荐答案
要收到通知的像文件的创建,打开事件,修改等考虑的 inotify的。从bash中使用它的好方法是用 inotifywait
命令 - 在这里 是它的手册页。它会阻止,直到你关心的事件发生。例如:
To get notified about events like file creation, opening, modifying etc. look into inotify. A good way to use it from bash is with the inotifywait
command - here is its man page. It will block until an event you care about happens. For example:
inotifywait -e create /path/to/watch
echo "ding!"
将丁当文件或目录在该路径被创建。请参阅手册页了解更多详情。
这篇关于我如何在Linux中创建一个文件监听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!