简体   繁体   中英

How do I create a file listener in linux?

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.

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!"

will ding when a file or directory gets created in that path. See the man page for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM