What is the proper way to use inotify?

后端 未结 4 960
一生所求
一生所求 2020-11-30 02:22

I want to use the inotify mechanism on Linux. I want my application to know when a file aaa was changed. Can you please provide me with a sample ho

4条回答
  •  生来不讨喜
    2020-11-30 02:59

    If all you need is a commandline application, there is one called inotifywait that watches files using inotify

    from terminal 1

    # touch cheese
    # while inotifywait -e modify cheese; do 
    >   echo someone touched my cheese
    > done
    

    from terminal 2

    echo lol >> cheese
    

    here is what is seen on terminal 1

    Setting up watches.
    Watches established.
    cheese MODIFY 
    someone touched my cheese
    Setting up watches.
    Watches established.
    

    Update: use with caution and see the comments.

提交回复
热议问题