initifywait –exclude does not fire when there is at least one not excluded file

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP

up vote
0
down vote

favorite

I am using this command to watch a directory:

inotifywait -r -e modify,create,delete --exclude ".*(.(git|idea)|(.*(___jb_tmp___|___jb_old___)))" my-dir

However, it does not work like I intend. What I want is that it does only NOT fire if every file that was changed is excluded. If there is at least one file that is NOT excluded and changes, then I want inotifywait to “fire”.

My overall plan is to push code to a remove server whenever a python file or something else that is relevant is changed. I do not want to push code when only meta files from my IDE (PyCharm) or git files are changed.

Is there a way to do this?

Right now inotifywait does not fire when I change a python file in PyCharm since there are some files changed that end with _jb_tmp_. However, if I change a python file by hand, it works (e.g. in nano or vim).

share|improve this question

  • Have you tried experimenting with simpler  --exclude values?
    – G-Man
    Nov 28 at 23:45

  • It is very hard to find simpler values that take care of all the files that PyCharm writes… Do you have a simpler idea?
    – Simon H
    Nov 29 at 0:15

  • It is really strange. When I use --exclude "(___jb_tmp___|___jb_old___)$" it fires when I save a file in PyCharm (but the event is called ‘.git/ CREATE index.lock’). When I use --exclude "(index.lock|___jb_tmp___|___jb_old___)$" and save a file, nothing happens. It looks like PyCharm is not really writing python files? But this makes no sense
    – Simon H
    Nov 29 at 0:24

  • I tried the following command: inotifywait -r -m -e modify,create,delete my-dir (note the -m flag to monitor and see all events) and found that there is no event for the .py files when I save them in pycharm. The only events: my-dir/patch_experts/ CREATE densenet.py___jb_tmp___ my-dir/patch_experts/ MODIFY densenet.py___jb_tmp___ my-dir/patch_experts/ DELETE densenet.py___jb_old___ my-dir/.idea/ CREATE workspace.xml___jb_tmp___ my-dir/.idea/ MODIFY workspace.xml___jb_tmp___ my-dir/.idea/ DELETE workspace.xml___jb_old___ my-dir/.git/ CREATE index.lock my-dir/.git/ DELETE index.lock
    – Simon H
    Nov 29 at 0:50

  • When I use sublime instead of PyCharm it works (I see ‘MODIFY main.py’). So the reason for the problem is PyCharm, but I have no idea why this happens
    – Simon H
    Nov 29 at 0:52

up vote
0
down vote

favorite

I am using this command to watch a directory:

inotifywait -r -e modify,create,delete --exclude ".*(.(git|idea)|(.*(___jb_tmp___|___jb_old___)))" my-dir

However, it does not work like I intend. What I want is that it does only NOT fire if every file that was changed is excluded. If there is at least one file that is NOT excluded and changes, then I want inotifywait to “fire”.

My overall plan is to push code to a remove server whenever a python file or something else that is relevant is changed. I do not want to push code when only meta files from my IDE (PyCharm) or git files are changed.

Is there a way to do this?

Right now inotifywait does not fire when I change a python file in PyCharm since there are some files changed that end with _jb_tmp_. However, if I change a python file by hand, it works (e.g. in nano or vim).

share|improve this question

  • Have you tried experimenting with simpler  --exclude values?
    – G-Man
    Nov 28 at 23:45

  • It is very hard to find simpler values that take care of all the files that PyCharm writes… Do you have a simpler idea?
    – Simon H
    Nov 29 at 0:15

  • It is really strange. When I use --exclude "(___jb_tmp___|___jb_old___)$" it fires when I save a file in PyCharm (but the event is called ‘.git/ CREATE index.lock’). When I use --exclude "(index.lock|___jb_tmp___|___jb_old___)$" and save a file, nothing happens. It looks like PyCharm is not really writing python files? But this makes no sense
    – Simon H
    Nov 29 at 0:24

  • I tried the following command: inotifywait -r -m -e modify,create,delete my-dir (note the -m flag to monitor and see all events) and found that there is no event for the .py files when I save them in pycharm. The only events: my-dir/patch_experts/ CREATE densenet.py___jb_tmp___ my-dir/patch_experts/ MODIFY densenet.py___jb_tmp___ my-dir/patch_experts/ DELETE densenet.py___jb_old___ my-dir/.idea/ CREATE workspace.xml___jb_tmp___ my-dir/.idea/ MODIFY workspace.xml___jb_tmp___ my-dir/.idea/ DELETE workspace.xml___jb_old___ my-dir/.git/ CREATE index.lock my-dir/.git/ DELETE index.lock
    – Simon H
    Nov 29 at 0:50

  • When I use sublime instead of PyCharm it works (I see ‘MODIFY main.py’). So the reason for the problem is PyCharm, but I have no idea why this happens
    – Simon H
    Nov 29 at 0:52

up vote
0
down vote

favorite

up vote
0
down vote

favorite

I am using this command to watch a directory:

inotifywait -r -e modify,create,delete --exclude ".*(.(git|idea)|(.*(___jb_tmp___|___jb_old___)))" my-dir

However, it does not work like I intend. What I want is that it does only NOT fire if every file that was changed is excluded. If there is at least one file that is NOT excluded and changes, then I want inotifywait to “fire”.

My overall plan is to push code to a remove server whenever a python file or something else that is relevant is changed. I do not want to push code when only meta files from my IDE (PyCharm) or git files are changed.

Is there a way to do this?

Right now inotifywait does not fire when I change a python file in PyCharm since there are some files changed that end with _jb_tmp_. However, if I change a python file by hand, it works (e.g. in nano or vim).

share|improve this question

I am using this command to watch a directory:

inotifywait -r -e modify,create,delete --exclude ".*(.(git|idea)|(.*(___jb_tmp___|___jb_old___)))" my-dir

However, it does not work like I intend. What I want is that it does only NOT fire if every file that was changed is excluded. If there is at least one file that is NOT excluded and changes, then I want inotifywait to “fire”.

My overall plan is to push code to a remove server whenever a python file or something else that is relevant is changed. I do not want to push code when only meta files from my IDE (PyCharm) or git files are changed.

Is there a way to do this?

Right now inotifywait does not fire when I change a python file in PyCharm since there are some files changed that end with _jb_tmp_. However, if I change a python file by hand, it works (e.g. in nano or vim).

ubuntu inotify

share|improve this question

share|improve this question

share|improve this question

share|improve this question

edited Nov 29 at 1:56

Rui F Ribeiro

38.4k1479128

38.4k1479128

asked Nov 28 at 23:11

Simon H

1012

1012

  • Have you tried experimenting with simpler  --exclude values?
    – G-Man
    Nov 28 at 23:45

  • It is very hard to find simpler values that take care of all the files that PyCharm writes… Do you have a simpler idea?
    – Simon H
    Nov 29 at 0:15

  • It is really strange. When I use --exclude "(___jb_tmp___|___jb_old___)$" it fires when I save a file in PyCharm (but the event is called ‘.git/ CREATE index.lock’). When I use --exclude "(index.lock|___jb_tmp___|___jb_old___)$" and save a file, nothing happens. It looks like PyCharm is not really writing python files? But this makes no sense
    – Simon H
    Nov 29 at 0:24

  • I tried the following command: inotifywait -r -m -e modify,create,delete my-dir (note the -m flag to monitor and see all events) and found that there is no event for the .py files when I save them in pycharm. The only events: my-dir/patch_experts/ CREATE densenet.py___jb_tmp___ my-dir/patch_experts/ MODIFY densenet.py___jb_tmp___ my-dir/patch_experts/ DELETE densenet.py___jb_old___ my-dir/.idea/ CREATE workspace.xml___jb_tmp___ my-dir/.idea/ MODIFY workspace.xml___jb_tmp___ my-dir/.idea/ DELETE workspace.xml___jb_old___ my-dir/.git/ CREATE index.lock my-dir/.git/ DELETE index.lock
    – Simon H
    Nov 29 at 0:50

  • When I use sublime instead of PyCharm it works (I see ‘MODIFY main.py’). So the reason for the problem is PyCharm, but I have no idea why this happens
    – Simon H
    Nov 29 at 0:52

  • Have you tried experimenting with simpler  --exclude values?
    – G-Man
    Nov 28 at 23:45

  • It is very hard to find simpler values that take care of all the files that PyCharm writes… Do you have a simpler idea?
    – Simon H
    Nov 29 at 0:15

  • It is really strange. When I use --exclude "(___jb_tmp___|___jb_old___)$" it fires when I save a file in PyCharm (but the event is called ‘.git/ CREATE index.lock’). When I use --exclude "(index.lock|___jb_tmp___|___jb_old___)$" and save a file, nothing happens. It looks like PyCharm is not really writing python files? But this makes no sense
    – Simon H
    Nov 29 at 0:24

  • I tried the following command: inotifywait -r -m -e modify,create,delete my-dir (note the -m flag to monitor and see all events) and found that there is no event for the .py files when I save them in pycharm. The only events: my-dir/patch_experts/ CREATE densenet.py___jb_tmp___ my-dir/patch_experts/ MODIFY densenet.py___jb_tmp___ my-dir/patch_experts/ DELETE densenet.py___jb_old___ my-dir/.idea/ CREATE workspace.xml___jb_tmp___ my-dir/.idea/ MODIFY workspace.xml___jb_tmp___ my-dir/.idea/ DELETE workspace.xml___jb_old___ my-dir/.git/ CREATE index.lock my-dir/.git/ DELETE index.lock
    – Simon H
    Nov 29 at 0:50

  • When I use sublime instead of PyCharm it works (I see ‘MODIFY main.py’). So the reason for the problem is PyCharm, but I have no idea why this happens
    – Simon H
    Nov 29 at 0:52

Have you tried experimenting with simpler  --exclude values?
– G-Man
Nov 28 at 23:45

Have you tried experimenting with simpler  --exclude values?
– G-Man
Nov 28 at 23:45

It is very hard to find simpler values that take care of all the files that PyCharm writes… Do you have a simpler idea?
– Simon H
Nov 29 at 0:15

It is very hard to find simpler values that take care of all the files that PyCharm writes… Do you have a simpler idea?
– Simon H
Nov 29 at 0:15

It is really strange. When I use --exclude "(___jb_tmp___|___jb_old___)$" it fires when I save a file in PyCharm (but the event is called ‘.git/ CREATE index.lock’). When I use --exclude "(index.lock|___jb_tmp___|___jb_old___)$" and save a file, nothing happens. It looks like PyCharm is not really writing python files? But this makes no sense
– Simon H
Nov 29 at 0:24

It is really strange. When I use --exclude "(___jb_tmp___|___jb_old___)$" it fires when I save a file in PyCharm (but the event is called ‘.git/ CREATE index.lock’). When I use --exclude "(index.lock|___jb_tmp___|___jb_old___)$" and save a file, nothing happens. It looks like PyCharm is not really writing python files? But this makes no sense
– Simon H
Nov 29 at 0:24

I tried the following command: inotifywait -r -m -e modify,create,delete my-dir (note the -m flag to monitor and see all events) and found that there is no event for the .py files when I save them in pycharm. The only events: my-dir/patch_experts/ CREATE densenet.py___jb_tmp___ my-dir/patch_experts/ MODIFY densenet.py___jb_tmp___ my-dir/patch_experts/ DELETE densenet.py___jb_old___ my-dir/.idea/ CREATE workspace.xml___jb_tmp___ my-dir/.idea/ MODIFY workspace.xml___jb_tmp___ my-dir/.idea/ DELETE workspace.xml___jb_old___ my-dir/.git/ CREATE index.lock my-dir/.git/ DELETE index.lock
– Simon H
Nov 29 at 0:50

I tried the following command: inotifywait -r -m -e modify,create,delete my-dir (note the -m flag to monitor and see all events) and found that there is no event for the .py files when I save them in pycharm. The only events: my-dir/patch_experts/ CREATE densenet.py___jb_tmp___ my-dir/patch_experts/ MODIFY densenet.py___jb_tmp___ my-dir/patch_experts/ DELETE densenet.py___jb_old___ my-dir/.idea/ CREATE workspace.xml___jb_tmp___ my-dir/.idea/ MODIFY workspace.xml___jb_tmp___ my-dir/.idea/ DELETE workspace.xml___jb_old___ my-dir/.git/ CREATE index.lock my-dir/.git/ DELETE index.lock
– Simon H
Nov 29 at 0:50

When I use sublime instead of PyCharm it works (I see ‘MODIFY main.py’). So the reason for the problem is PyCharm, but I have no idea why this happens
– Simon H
Nov 29 at 0:52

When I use sublime instead of PyCharm it works (I see ‘MODIFY main.py’). So the reason for the problem is PyCharm, but I have no idea why this happens
– Simon H
Nov 29 at 0:52

1 Answer
1

active

oldest

votes

up vote
0
down vote

As stated in the comments to my question, I found that the problem was not caused by inotifywait but by PyCharm. It turned out that PyCharm has an option called “safe write” that tells the IDE to write changes to temporary files first and if this succeeds, it deletes the original file and renames the tempory file to the original file name.

This is why inotifywait only sees events like these:

$ inotifywait -r -m -e modify,create,delete my-dir

my-dir/ CREATE main.py___jb_tmp___ 
my-dir/ MODIFY main.py___jb_tmp___ 
my-dir/ DELETE main.py___jb_old___ 
my-dir/.idea/ CREATE workspace.xml___jb_tmp___ 
my-dir/.idea/ MODIFY workspace.xml___jb_tmp___ 
my-dir/.idea/ DELETE workspace.xml___jb_old___ 
my-dir/.git/ CREATE index.lock 
my-dir/.git/ DELETE index.lock

So I disabled safe write in PyCharm and now use this command:

inotifywait -r -e modify,create,delete --exclude ".*(.git|.idea)" my-dir

This is doing exactly what I want. The events I see from inotifywait are like this:

my-dir/ MODIFY main.py

share|improve this answer

    Your Answer

    StackExchange.ready(function() {
    var channelOptions = {
    tags: “”.split(” “),
    id: “106”
    };
    initTagRenderer(“”.split(” “), “”.split(” “), channelOptions);

    StackExchange.using(“externalEditor”, function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using(“snippets”, function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: ‘answer’,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: “”,
    imageUploader: {
    brandingHtml: “Powered by u003ca class=”icon-imgur-white” href=”https://imgur.com/”u003eu003c/au003e”,
    contentPolicyHtml: “User contributions licensed under u003ca href=”https://creativecommons.org/licenses/by-sa/3.0/”u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href=”https://stackoverflow.com/legal/content-policy”u003e(content policy)u003c/au003e”,
    allowUrls: true
    },
    onDemand: true,
    discardSelector: “.discard-answer”
    ,immediatelyShowMarkdownHelp:true
    });

    }
    });

    draft saved
    draft discarded

    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin(‘.new-post-login’, ‘https%3a%2f%2funix.stackexchange.com%2fquestions%2f484792%2finitifywait-exclude-does-not-fire-when-there-is-at-least-one-not-excluded-file%23new-answer’, ‘question_page’);
    }
    );

    Post as a guest

    Required, but never shown

    1 Answer
    1

    active

    oldest

    votes

    1 Answer
    1

    active

    oldest

    votes

    active

    oldest

    votes

    active

    oldest

    votes

    up vote
    0
    down vote

    As stated in the comments to my question, I found that the problem was not caused by inotifywait but by PyCharm. It turned out that PyCharm has an option called “safe write” that tells the IDE to write changes to temporary files first and if this succeeds, it deletes the original file and renames the tempory file to the original file name.

    This is why inotifywait only sees events like these:

    $ inotifywait -r -m -e modify,create,delete my-dir
    
    my-dir/ CREATE main.py___jb_tmp___ 
    my-dir/ MODIFY main.py___jb_tmp___ 
    my-dir/ DELETE main.py___jb_old___ 
    my-dir/.idea/ CREATE workspace.xml___jb_tmp___ 
    my-dir/.idea/ MODIFY workspace.xml___jb_tmp___ 
    my-dir/.idea/ DELETE workspace.xml___jb_old___ 
    my-dir/.git/ CREATE index.lock 
    my-dir/.git/ DELETE index.lock
    

    So I disabled safe write in PyCharm and now use this command:

    inotifywait -r -e modify,create,delete --exclude ".*(.git|.idea)" my-dir
    

    This is doing exactly what I want. The events I see from inotifywait are like this:

    my-dir/ MODIFY main.py

    share|improve this answer

      up vote
      0
      down vote

      As stated in the comments to my question, I found that the problem was not caused by inotifywait but by PyCharm. It turned out that PyCharm has an option called “safe write” that tells the IDE to write changes to temporary files first and if this succeeds, it deletes the original file and renames the tempory file to the original file name.

      This is why inotifywait only sees events like these:

      $ inotifywait -r -m -e modify,create,delete my-dir
      
      my-dir/ CREATE main.py___jb_tmp___ 
      my-dir/ MODIFY main.py___jb_tmp___ 
      my-dir/ DELETE main.py___jb_old___ 
      my-dir/.idea/ CREATE workspace.xml___jb_tmp___ 
      my-dir/.idea/ MODIFY workspace.xml___jb_tmp___ 
      my-dir/.idea/ DELETE workspace.xml___jb_old___ 
      my-dir/.git/ CREATE index.lock 
      my-dir/.git/ DELETE index.lock
      

      So I disabled safe write in PyCharm and now use this command:

      inotifywait -r -e modify,create,delete --exclude ".*(.git|.idea)" my-dir
      

      This is doing exactly what I want. The events I see from inotifywait are like this:

      my-dir/ MODIFY main.py

      share|improve this answer

        up vote
        0
        down vote

        up vote
        0
        down vote

        As stated in the comments to my question, I found that the problem was not caused by inotifywait but by PyCharm. It turned out that PyCharm has an option called “safe write” that tells the IDE to write changes to temporary files first and if this succeeds, it deletes the original file and renames the tempory file to the original file name.

        This is why inotifywait only sees events like these:

        $ inotifywait -r -m -e modify,create,delete my-dir
        
        my-dir/ CREATE main.py___jb_tmp___ 
        my-dir/ MODIFY main.py___jb_tmp___ 
        my-dir/ DELETE main.py___jb_old___ 
        my-dir/.idea/ CREATE workspace.xml___jb_tmp___ 
        my-dir/.idea/ MODIFY workspace.xml___jb_tmp___ 
        my-dir/.idea/ DELETE workspace.xml___jb_old___ 
        my-dir/.git/ CREATE index.lock 
        my-dir/.git/ DELETE index.lock
        

        So I disabled safe write in PyCharm and now use this command:

        inotifywait -r -e modify,create,delete --exclude ".*(.git|.idea)" my-dir
        

        This is doing exactly what I want. The events I see from inotifywait are like this:

        my-dir/ MODIFY main.py

        share|improve this answer

        As stated in the comments to my question, I found that the problem was not caused by inotifywait but by PyCharm. It turned out that PyCharm has an option called “safe write” that tells the IDE to write changes to temporary files first and if this succeeds, it deletes the original file and renames the tempory file to the original file name.

        This is why inotifywait only sees events like these:

        $ inotifywait -r -m -e modify,create,delete my-dir
        
        my-dir/ CREATE main.py___jb_tmp___ 
        my-dir/ MODIFY main.py___jb_tmp___ 
        my-dir/ DELETE main.py___jb_old___ 
        my-dir/.idea/ CREATE workspace.xml___jb_tmp___ 
        my-dir/.idea/ MODIFY workspace.xml___jb_tmp___ 
        my-dir/.idea/ DELETE workspace.xml___jb_old___ 
        my-dir/.git/ CREATE index.lock 
        my-dir/.git/ DELETE index.lock
        

        So I disabled safe write in PyCharm and now use this command:

        inotifywait -r -e modify,create,delete --exclude ".*(.git|.idea)" my-dir
        

        This is doing exactly what I want. The events I see from inotifywait are like this:

        my-dir/ MODIFY main.py

        share|improve this answer

        share|improve this answer

        share|improve this answer

        answered Nov 29 at 1:08

        Simon H

        1012

        1012

            draft saved
            draft discarded

            Thanks for contributing an answer to Unix & Linux Stack Exchange!

            • Please be sure to answer the question. Provide details and share your research!

            But avoid

            • Asking for help, clarification, or responding to other answers.
            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.

            Some of your past answers have not been well-received, and you’re in danger of being blocked from answering.

            Please pay close attention to the following guidance:

            • Please be sure to answer the question. Provide details and share your research!

            But avoid

            • Asking for help, clarification, or responding to other answers.
            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.

            draft saved

            draft discarded

            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin(‘.new-post-login’, ‘https%3a%2f%2funix.stackexchange.com%2fquestions%2f484792%2finitifywait-exclude-does-not-fire-when-there-is-at-least-one-not-excluded-file%23new-answer’, ‘question_page’);
            }
            );

            Post as a guest

            Required, but never shown

            Required, but never shown

            Required, but never shown

            Required, but never shown

            Required, but never shown

            Required, but never shown

            Required, but never shown

            Required, but never shown

            Required, but never shown

            Related Post

            Leave a Reply

            Your email address will not be published. Required fields are marked *