inotifywait, inotifywatch and incron: A package deal

I have two or three related titles I’d like to combine today, but I know I probably won’t do justice to any of them. The first two are inotifywait and inotifywatch from the inotify-tools suite, and the other is incron. All of those rely on inotify‘s filesystem notification to alert you when something in storage has changed.

We’ve seen tools like this before — like wendy or or fsniper or entr — and for the most part, everybody has their own ways of doing things. inotifywait is something valadil mentioned a few months ago, and his (her?) example was good as a starting point. I’ve modified it a little bit:

kmandla@6m47421: ~$ inotifywait vimwiki/ && echo "File changed!"

The net result being:


inotifywatch works a little differently, keeping track of changes and events and offering a table of results at the end.

kmandla@6m47421: ~$ inotifywatch -t 30 -r vimwiki/*
Establishing watches...
Finished establishing watches, now collecting statistics.
total  access  attrib  close_write  close_nowrite  open  delete_self  filename
25     5       0       0            10             10    0            vimwiki/
15     3       0       0            6              6     0            vimwiki/
15     3       0       0            6              6     0            vimwiki/
10     2       0       0            4              4     0            vimwiki/
5      1       0       0            2              2     0            vimwiki/
5      1       0       0            2              2     0            vimwiki/
5      1       0       0            2              2     0            vimwiki/
5      1       0       0            2              2     0            vimwiki/
5      1       0       0            2              2     0            vimwiki/
5      1       0       0            2              2     0            vimwiki/
4      0       1       1            0              0     1            vimwiki/
4      0       0       0            2              2     0            vimwiki/

The main point should be visible here: That you can collect statistics on folder or file usage just by letting inotifywatch run, rather than hinging an action on a file changing.

incron is the last one of these three, and I do it the most disservice by not having anything to show for it. There are two reasons for that; one is that it would take quite a bit to get it configured and working, and second, I couldn’t show you anything specifically incron was doing.

That’s because incron is a cron-style daemon that relies on file changes to trigger events, rather than time periods … which does make me wonder if the “cron” suffix — which I always took to be a mnemonic for “chron,” as in “chronological” — is really appropriate.

Naming conventions aside, incron would only trigger some other program, and I’d be handing you a screenshot of an unrelated program, and saying, “That’s incron. See? See?” ๐Ÿ™„

Regardless, if you find yourself triggering a lot of specific events on a variety of file changes, you might want to consider setting up an incron array, rather than a battery of inotifywait commands.

I think that’s good for now. Any one of these tools could be an alternative to the three or four home-grown ones we’ve seen in the past. Depending on your needs and resources, of course. ๐Ÿ˜‰

3 thoughts on “inotifywait, inotifywatch and incron: A package deal

    1. K.Mandla Post author

      I hope that’s a good reaction. ๐Ÿ™‚ It took me a little time to wrap my head around it, but once I saw how it was arranged it makes a lot of sense. Have fun with it. ๐Ÿ˜‰

  1. Pingback: Bonus: 2014 in review | Inconsolation

Comments are closed.