How can I “watch” a file for modification / change

2019-01-08 15:48发布

This question already has an answer here:

I would like to invoke my chrome or firefox browser when a file that I specify is modified. How could I "watch" that file to do something when it gets modified?

Programmatically it seems the steps are.. basically set a never ending interval every second or so and cache the initial modification date, then compare the date every second, when it changes invoke X.

标签: python linux
7条回答
欢心
2楼-- · 2019-01-08 16:38

The Linux Kernel has a file monitoring API called inotify. A python binding is pyinotify.

With it, you can build what you want.

查看更多
登录 后发表回答