Monitor directory content change

前端 未结 2 404
终归单人心
终归单人心 2020-12-20 08:01

I\'m writing a bash script, and I\'d like to monitor file changes into a directory (adding, deleting and renaming) and performing different action accordingly.

Is th

相关标签:
2条回答
  • 2020-12-20 08:40

    Just an idea. If you are allowed to do it only in bash, then you can generate a md5sum on directory contents. Probably you can have file-name,modify-time,inode-modify-time etc in that directory.

    0 讨论(0)
  • 2020-12-20 08:41

    You can use the inotifywait command (assuming your distribution supports inotify, which most do):

    inotifywait -m -r --format '%f' -e modify -e move -e create -e delete ~/test | while read line
    do
        echo "File: $line"
    done
    
    0 讨论(0)
提交回复
热议问题