What is the proper way to use inotify?

Documentation ( from Monitor file system activity with inotify ) The inotify C API inotify provides three system calls to build file system monitors of all kinds: inotify_init() creates an instance of the inotify subsystem in the kernel and returns a file descriptor on success and -1 on failure. Like other system calls, if inotify_init() … Read more

How to monitor a complete directory tree for changes in Linux?

I’ve done something similar using the inotifywait tool: #!/bin/bash while true; do inotifywait -e modify,create,delete -r /path/to/your/dir && \ <some command to execute when a file event is recorded> done This will setup recursive directory watches on the entire tree and allow you to execute a command when something changes. If you just want to … Read more

inotify with NFS

inotify requires support from the kernel to work. When an application tracks a directory, it asks the kernel to inform it when those changes occur. When the change occurs, in addition to writing those changes to disk, the kernel also notifies the watching process. On a remote NFS machine, the change is not visible to … Read more

Is there anything like inotify on Windows?

If you’re using .net, use FileSystemWatcher. More info here: http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx If you’re using C, use FindFirstChangeNotification, FindNextChangeNotification, ReadDirectoryChangesW. More info here: http://msdn.microsoft.com/en-us/library/aa365261(VS.85).aspx On OSX, the relevant api is the fsevents api. They’re all subtly different from one another, and they all have questionable reliability in edge cases. In general, you can’t depend on these apis … Read more

Is there a command like “watch” or “inotifywait” on the Mac?

fswatch fswatch is a small program using the Mac OS X FSEvents API to monitor a directory. When an event about any change to that directory is received, the specified shell command is executed by /bin/bash If you’re on GNU/Linux, inotifywatch (part of the inotify-tools package on most distributions) provides similar functionality. Update: fswatch can … Read more

How to retrieve a module’s path?

import a_module print(a_module.__file__) Will actually give you the path to the .pyc file that was loaded, at least on Mac OS X. So I guess you can do: import os path = os.path.abspath(a_module.__file__) You can also try: path = os.path.dirname(a_module.__file__) To get the module’s directory.