Monitor directory listing for changes?

前端 未结 2 1377
说谎
说谎 2021-01-12 20:40

On a unix system, how do I monitor (like how \'tail\' works) a directory for changes made to files - either new ones created, or size changes, etc.

Looking for a com

2条回答
  •  猫巷女王i
    2021-01-12 21:40

    you can craft your own then if you don't want to install tools. Just an idea. Create a base line file of your directory using find command. Use a loop or cron job, find the directory using the same parameters, and check the new file against the base line file. Use a tool like diff to get the differences..

    eg

    find /path [other options] >> baseline.txt 
    while true #or use a cron job
    do
      find /path [same options] >> listing.txt
      diff baseline.txt listing.txt
      # do processing here...
      mv listing.txt baseline.txt  # update the baseline.
      sleep 60
    done
    

提交回复
热议问题