I believe most operating systems have a mechanism for this. E.g. on macOS it's called fsevents, Linux has inotify
I believe most operating systems have a mechanism for this. E.g. on macOS it's called fsevents, Linux has inotify