Does inotifywait on Linux allow collection of events over a timeout period?

cf. FSEvents on OSX, which by default collects FS events over 1 second (timeout configurable) before firing off the event.

This has the benefit of collecting a series of filesystem changes into a single event (so the script won't run more than it needs to), at the cost of latency.

For instance, saving a file in Vim modifies many temp files (it tends to delete a buffer file, update an undo file, and also creates and then erases a test file called 4193) in addition to the file itself. On OSX with a small tool that uses this API such as my fork of fswatch, all of these can get collapsed into one "batch event", whereas with inotifywait -m all the events that I specify come over the stream in separate lines making it not simple to group without external processing.

I'm pretty sure the solution is to just to wrap it and do this processing but I was hoping there was a hidden feature to specify a timeout like the FSEvents allows for.

Answers

I actually am starting to believe that this sort of thing should not be within the scope of inotify's features.

I haven't quite found the proper solution, but it looks to me like there is some form of elegant way to do it. Here's my starting point (which quits if nothing is seen in a second, i want to have something accumulate stuff over one second)

Currently doing some testing with this. Here's some test scripting I've got working quite well.

group=0
( for val in {1..10}; do echo "$RANDOM/10000" | bc | xargs sleep; echo $val; done ) |  while true; do while read -t 1 line; do echo "read $group $line"; done; ((group++)); done
Posted on by Steven Lu