Any ways to show file changes (with pyinotify for example)?

泄露秘密 提交于 2021-02-08 06:30:08

问题


Is there any way to print a watched file modification ? let's take an example: I'm monitoring file.txt, Pyinotify can tell me that it has been modified, but It can't seem to be able to output what changes occured ? Am I wrong ? How can I see what changes has been made to a file that I'm monitoring ?

Big thanks in advance, sorry for my bad english.


回答1:


The inotify mechanism does not embed the deltas in the event, because it should compute it before saving the files and this could affect performance since this information is not usually needed.

You could use an approach like:

  • Read the data from file.txt and store it in a variable (or another file if persistence is needed).

  • Listen for change events using pyinotify or watchdog.

  • When the event is fired use difflib to check the deltas from the previous snapshot that you stored and the current file data.



来源:https://stackoverflow.com/questions/25350252/any-ways-to-show-file-changes-with-pyinotify-for-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!