How to create a file listener on Linux?

I am trying to create a listener in a specific directory that runs the Linux command whenever a file appears in this path. For example, whenever a file appears in a directory such as C: / home /, I would like to read a line of text from that file, and then run another command. I was thinking about using a loop, but that seems inefficient.

+6
source share
1 answer

To receive notifications about events such as file creation, opening, changing, etc., see inotify . A good way to use it from bash is the inotifywait command - here is its man page. It will block until an event you worry about occurs. For example:

 inotifywait -e create /path/to/watch echo "ding!" 

will be displayed when creating a file or directory in this path. See the man page for more details.

+11
source

All Articles