4

It seems that inotifywait works with exclude lists only.

I have seen the workarounds, but don't like them:

How to use inotifywait to watch a directory for creation of files of a specific extension

Is there a tool which allows listening for *.json files only (without workarounds)?

I want to call a tool (without wrapping it in a script). The work-around of above question needs a loop. I would like to avoid this, if possible.

Update: Since there seems to be no tool which can do this out-of-the-box I wrote a simple Python script and used the lib pyinotify

guettli
  • 1,389
  • 1
    You will not find anything better than inotify with custom treatment to only considers the files you have interest in. Also file extension are not consider to identify files in Linux. They only exists to help readability for human. – Kiwy Sep 12 '18 at 14:23
  • @Kiwy I am searching an alternative to inotifywait. I search for a different tool. And of course this will use inotify. I am not searching an alternative to inotify. – guettli Sep 12 '18 at 14:34
  • 1
    I recommand the python library inotify. it works quiet well and I'm sure it could handle filtering – Kiwy Sep 12 '18 at 14:40
  • @Kiwy thank you for your hint (Python inotify lib). In this case it would be a bit easier if you could just install a tool which solves this. I could solve this by writing a small python script, but I would like to avoid coding in this case. – guettli Sep 17 '18 at 07:31
  • 1
    In the link you posted for workarounds I think it's clear that the accepted answer is awful, but the other answer seems straightforward. What is it about that answer that you don't like? That might affect an answer here. – Tony Sep 20 '18 at 23:28
  • @Tony I updated the question. Is it clear now? If not, please tell me. – guettli Sep 21 '18 at 06:54
  • What's wrong with the second answer on that question? – ams Sep 21 '18 at 15:28
  • @ams the answer from Jonas Earendel is valid. It works. It is a loop. It is programming. It is a work-around. – guettli Sep 21 '18 at 18:13
  • Look closer. It uses a loop to wrap a message around the filename, but that's all. The filtering is fine by inotifywait. – ams Sep 21 '18 at 19:25
  • @ams yes, you are right. Nevertheless it is a work-around, not a solution. – guettli Sep 21 '18 at 19:30
  • So.... what do you expect the tool to do when a file changes, exactly? You made it sound like inotifywait was missing one feature, but now it's just the wrong thing. – ams Sep 21 '18 at 19:41
  • @ams most tools can work both ways: They take all files, except the files in the exclude list. Or they take not file, except the files from the include list. Unfortunately I can't find a inotify tool which works with a include list. If you google for it, you find 100 different work-around for this issue. I think it is sad, that there is no solution, but only work-arounds. – guettli Sep 21 '18 at 20:04
  • Oh, so putting "[^ ]" around each letter is what makes it unusable for you? Apparently there's a patch for that, but the maintainer isn't interested. – ams Sep 21 '18 at 22:25
  • 2
    Umm, that git repo has an --include and --includei option, but it's not in the binary I have. Confused now?! – ams Sep 21 '18 at 22:36
  • The "real solution" would amount to moving the workaround inside inotifywait. That is because the inw layer receives an event, and at that point it does not "know" the filename, much less the extension. So it has to perform a filtering. You just want the filter to work in reverse. It is doable, but for it not to be a "workaround" as defined by the answered question, it would need to be done inside the inw code. I think overall efficiency wouldn't probably be so different. – LSerni Sep 24 '18 at 07:12

0 Answers0