简体   繁体   中英

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

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.

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.

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