Check whether a file is opened or not

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











up vote
0
down vote

favorite












I have a folder, inside of which there are a lot of files. I was looking for a way to check whether any file inside that folder has been opened or not. If it is open, I need to get notified. I know this can be done using inotify-wait but have not been able to do so.



Here is my script



MONITORDIR="/home/aniketshivamtiwari/Downloads/Projects"
inotifywait -m -r -e create --format '%w%f' "$MONITORDIR" | while read NEWFILE
do
echo "File $NEWFILE has been opened"
done






share|improve this question






















  • Closely related: Using inotify to monitor a directory but not working 100%
    – Michael Homer
    Oct 15 '17 at 6:40






  • 1




    Why do you use create and not open if what you want is to monitor wheter files inside the directory are opened? Couldn't you use something like this instead: inotifywait -m -q -e open --format '%w%f' $MONITORDIR/*?
    – Rastapopoulos
    Oct 15 '17 at 8:26











  • @Rastapopoulos - Your solution worked
    – Aniket Shivam Tiwari
    Oct 15 '17 at 13:49














up vote
0
down vote

favorite












I have a folder, inside of which there are a lot of files. I was looking for a way to check whether any file inside that folder has been opened or not. If it is open, I need to get notified. I know this can be done using inotify-wait but have not been able to do so.



Here is my script



MONITORDIR="/home/aniketshivamtiwari/Downloads/Projects"
inotifywait -m -r -e create --format '%w%f' "$MONITORDIR" | while read NEWFILE
do
echo "File $NEWFILE has been opened"
done






share|improve this question






















  • Closely related: Using inotify to monitor a directory but not working 100%
    – Michael Homer
    Oct 15 '17 at 6:40






  • 1




    Why do you use create and not open if what you want is to monitor wheter files inside the directory are opened? Couldn't you use something like this instead: inotifywait -m -q -e open --format '%w%f' $MONITORDIR/*?
    – Rastapopoulos
    Oct 15 '17 at 8:26











  • @Rastapopoulos - Your solution worked
    – Aniket Shivam Tiwari
    Oct 15 '17 at 13:49












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a folder, inside of which there are a lot of files. I was looking for a way to check whether any file inside that folder has been opened or not. If it is open, I need to get notified. I know this can be done using inotify-wait but have not been able to do so.



Here is my script



MONITORDIR="/home/aniketshivamtiwari/Downloads/Projects"
inotifywait -m -r -e create --format '%w%f' "$MONITORDIR" | while read NEWFILE
do
echo "File $NEWFILE has been opened"
done






share|improve this question














I have a folder, inside of which there are a lot of files. I was looking for a way to check whether any file inside that folder has been opened or not. If it is open, I need to get notified. I know this can be done using inotify-wait but have not been able to do so.



Here is my script



MONITORDIR="/home/aniketshivamtiwari/Downloads/Projects"
inotifywait -m -r -e create --format '%w%f' "$MONITORDIR" | while read NEWFILE
do
echo "File $NEWFILE has been opened"
done








share|improve this question













share|improve this question




share|improve this question








edited Oct 15 '17 at 6:42









Anthon

58.6k1796159




58.6k1796159










asked Oct 15 '17 at 6:31









Aniket Shivam Tiwari

1113




1113











  • Closely related: Using inotify to monitor a directory but not working 100%
    – Michael Homer
    Oct 15 '17 at 6:40






  • 1




    Why do you use create and not open if what you want is to monitor wheter files inside the directory are opened? Couldn't you use something like this instead: inotifywait -m -q -e open --format '%w%f' $MONITORDIR/*?
    – Rastapopoulos
    Oct 15 '17 at 8:26











  • @Rastapopoulos - Your solution worked
    – Aniket Shivam Tiwari
    Oct 15 '17 at 13:49
















  • Closely related: Using inotify to monitor a directory but not working 100%
    – Michael Homer
    Oct 15 '17 at 6:40






  • 1




    Why do you use create and not open if what you want is to monitor wheter files inside the directory are opened? Couldn't you use something like this instead: inotifywait -m -q -e open --format '%w%f' $MONITORDIR/*?
    – Rastapopoulos
    Oct 15 '17 at 8:26











  • @Rastapopoulos - Your solution worked
    – Aniket Shivam Tiwari
    Oct 15 '17 at 13:49















Closely related: Using inotify to monitor a directory but not working 100%
– Michael Homer
Oct 15 '17 at 6:40




Closely related: Using inotify to monitor a directory but not working 100%
– Michael Homer
Oct 15 '17 at 6:40




1




1




Why do you use create and not open if what you want is to monitor wheter files inside the directory are opened? Couldn't you use something like this instead: inotifywait -m -q -e open --format '%w%f' $MONITORDIR/*?
– Rastapopoulos
Oct 15 '17 at 8:26





Why do you use create and not open if what you want is to monitor wheter files inside the directory are opened? Couldn't you use something like this instead: inotifywait -m -q -e open --format '%w%f' $MONITORDIR/*?
– Rastapopoulos
Oct 15 '17 at 8:26













@Rastapopoulos - Your solution worked
– Aniket Shivam Tiwari
Oct 15 '17 at 13:49




@Rastapopoulos - Your solution worked
– Aniket Shivam Tiwari
Oct 15 '17 at 13:49










1 Answer
1






active

oldest

votes

















up vote
1
down vote













Here is the solution
First install sudo apt-get install inotify-tools



MONITORDIR="path/to/the/folder"
inotifywait -m -q -e open --format '%w%f' $MONITORDIR/* | while read NEWFILE
do
echo "File $NEWFILE has been open"
done





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: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    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%2f398205%2fcheck-whether-a-file-is-opened-or-not%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    Here is the solution
    First install sudo apt-get install inotify-tools



    MONITORDIR="path/to/the/folder"
    inotifywait -m -q -e open --format '%w%f' $MONITORDIR/* | while read NEWFILE
    do
    echo "File $NEWFILE has been open"
    done





    share|improve this answer


























      up vote
      1
      down vote













      Here is the solution
      First install sudo apt-get install inotify-tools



      MONITORDIR="path/to/the/folder"
      inotifywait -m -q -e open --format '%w%f' $MONITORDIR/* | while read NEWFILE
      do
      echo "File $NEWFILE has been open"
      done





      share|improve this answer
























        up vote
        1
        down vote










        up vote
        1
        down vote









        Here is the solution
        First install sudo apt-get install inotify-tools



        MONITORDIR="path/to/the/folder"
        inotifywait -m -q -e open --format '%w%f' $MONITORDIR/* | while read NEWFILE
        do
        echo "File $NEWFILE has been open"
        done





        share|improve this answer














        Here is the solution
        First install sudo apt-get install inotify-tools



        MONITORDIR="path/to/the/folder"
        inotifywait -m -q -e open --format '%w%f' $MONITORDIR/* | while read NEWFILE
        do
        echo "File $NEWFILE has been open"
        done






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Oct 15 '17 at 16:07

























        answered Oct 15 '17 at 13:49









        Aniket Shivam Tiwari

        1113




        1113



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f398205%2fcheck-whether-a-file-is-opened-or-not%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Christian Cage

            How to properly install USB display driver for Fresco Logic FL2000DX on Ubuntu?