In Linux, this is done with inotify.
Path units in systemd present inotify, but their use is somewhat constrained.
The incron utility is more flexible.