Determine the files/directories changed as a result of running a command

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











up vote
2
down vote

favorite












If I run a command in bash, is there any way to determine which files and directories were modified as a result of running that command?



For example, if i run:



export $MYDIR="/home/users/myuser/"
touch $MY_DIR/*


I would like to be able to list the files that were modified:



/home/users/myuser/file1
/home/users/myuser/file2
/home/users/myuser/file3


But not specifically for touch. I would like the solution to be general for any command.



Is this possible?










share|improve this question

























    up vote
    2
    down vote

    favorite












    If I run a command in bash, is there any way to determine which files and directories were modified as a result of running that command?



    For example, if i run:



    export $MYDIR="/home/users/myuser/"
    touch $MY_DIR/*


    I would like to be able to list the files that were modified:



    /home/users/myuser/file1
    /home/users/myuser/file2
    /home/users/myuser/file3


    But not specifically for touch. I would like the solution to be general for any command.



    Is this possible?










    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      If I run a command in bash, is there any way to determine which files and directories were modified as a result of running that command?



      For example, if i run:



      export $MYDIR="/home/users/myuser/"
      touch $MY_DIR/*


      I would like to be able to list the files that were modified:



      /home/users/myuser/file1
      /home/users/myuser/file2
      /home/users/myuser/file3


      But not specifically for touch. I would like the solution to be general for any command.



      Is this possible?










      share|improve this question













      If I run a command in bash, is there any way to determine which files and directories were modified as a result of running that command?



      For example, if i run:



      export $MYDIR="/home/users/myuser/"
      touch $MY_DIR/*


      I would like to be able to list the files that were modified:



      /home/users/myuser/file1
      /home/users/myuser/file2
      /home/users/myuser/file3


      But not specifically for touch. I would like the solution to be general for any command.



      Is this possible?







      linux bash shell






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 21 at 6:33









      moebius

      1135




      1135




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          There are a couple of tools which I quite like for this kind of use case:




          • maybe will run a command, but fake any modification to the file system (pretend it succeeded without performing it, and log it), then display a list of all the changes; you can then decide whether to run the command again — it’s not perfect, see the list of issues, but it’s good enough in many cases;


          • LoggedFS provides a logging file system overlay, which lets all changes to a file system go through but logs them, in a configurable manner (see LoggedFS configuration file syntax for details).

          Other tools commonly used to trace file system operations include inotifywait and auditd; see Linux file access monitoring for details.






          share|improve this answer



























            up vote
            1
            down vote













            For a basic / simplistic solution, how about creating a file first, and then, after your operation, running a find to display files newer than said file ?



            touch /tmp/myfile
            ( do stuff )
            find $MY_DIR -newer /tmp/myfile


            As @roaima points out, this only address your "which files and directories were modified as a result" requirement : it would not identify files that were removed.






            share|improve this answer


















            • 1




              You'd need a "before and after" to catch a tool that removed files
              – roaima
              Aug 21 at 8:18










            • Note that it's zsh syntax. With bash (see tag in OP's question), you'd need find "$MY_DIR". find $MY_DIR would only make sense in bash if $MY_DIR was meant to contain a $IFS-separated list of file patterns that you intended to expand. (:-b)
              – Stéphane Chazelas
              Aug 27 at 18:18











            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%2f463785%2fdetermine-the-files-directories-changed-as-a-result-of-running-a-command%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote



            accepted










            There are a couple of tools which I quite like for this kind of use case:




            • maybe will run a command, but fake any modification to the file system (pretend it succeeded without performing it, and log it), then display a list of all the changes; you can then decide whether to run the command again — it’s not perfect, see the list of issues, but it’s good enough in many cases;


            • LoggedFS provides a logging file system overlay, which lets all changes to a file system go through but logs them, in a configurable manner (see LoggedFS configuration file syntax for details).

            Other tools commonly used to trace file system operations include inotifywait and auditd; see Linux file access monitoring for details.






            share|improve this answer
























              up vote
              2
              down vote



              accepted










              There are a couple of tools which I quite like for this kind of use case:




              • maybe will run a command, but fake any modification to the file system (pretend it succeeded without performing it, and log it), then display a list of all the changes; you can then decide whether to run the command again — it’s not perfect, see the list of issues, but it’s good enough in many cases;


              • LoggedFS provides a logging file system overlay, which lets all changes to a file system go through but logs them, in a configurable manner (see LoggedFS configuration file syntax for details).

              Other tools commonly used to trace file system operations include inotifywait and auditd; see Linux file access monitoring for details.






              share|improve this answer






















                up vote
                2
                down vote



                accepted







                up vote
                2
                down vote



                accepted






                There are a couple of tools which I quite like for this kind of use case:




                • maybe will run a command, but fake any modification to the file system (pretend it succeeded without performing it, and log it), then display a list of all the changes; you can then decide whether to run the command again — it’s not perfect, see the list of issues, but it’s good enough in many cases;


                • LoggedFS provides a logging file system overlay, which lets all changes to a file system go through but logs them, in a configurable manner (see LoggedFS configuration file syntax for details).

                Other tools commonly used to trace file system operations include inotifywait and auditd; see Linux file access monitoring for details.






                share|improve this answer












                There are a couple of tools which I quite like for this kind of use case:




                • maybe will run a command, but fake any modification to the file system (pretend it succeeded without performing it, and log it), then display a list of all the changes; you can then decide whether to run the command again — it’s not perfect, see the list of issues, but it’s good enough in many cases;


                • LoggedFS provides a logging file system overlay, which lets all changes to a file system go through but logs them, in a configurable manner (see LoggedFS configuration file syntax for details).

                Other tools commonly used to trace file system operations include inotifywait and auditd; see Linux file access monitoring for details.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 21 at 8:17









                Stephen Kitt

                146k22320386




                146k22320386






















                    up vote
                    1
                    down vote













                    For a basic / simplistic solution, how about creating a file first, and then, after your operation, running a find to display files newer than said file ?



                    touch /tmp/myfile
                    ( do stuff )
                    find $MY_DIR -newer /tmp/myfile


                    As @roaima points out, this only address your "which files and directories were modified as a result" requirement : it would not identify files that were removed.






                    share|improve this answer


















                    • 1




                      You'd need a "before and after" to catch a tool that removed files
                      – roaima
                      Aug 21 at 8:18










                    • Note that it's zsh syntax. With bash (see tag in OP's question), you'd need find "$MY_DIR". find $MY_DIR would only make sense in bash if $MY_DIR was meant to contain a $IFS-separated list of file patterns that you intended to expand. (:-b)
                      – Stéphane Chazelas
                      Aug 27 at 18:18















                    up vote
                    1
                    down vote













                    For a basic / simplistic solution, how about creating a file first, and then, after your operation, running a find to display files newer than said file ?



                    touch /tmp/myfile
                    ( do stuff )
                    find $MY_DIR -newer /tmp/myfile


                    As @roaima points out, this only address your "which files and directories were modified as a result" requirement : it would not identify files that were removed.






                    share|improve this answer


















                    • 1




                      You'd need a "before and after" to catch a tool that removed files
                      – roaima
                      Aug 21 at 8:18










                    • Note that it's zsh syntax. With bash (see tag in OP's question), you'd need find "$MY_DIR". find $MY_DIR would only make sense in bash if $MY_DIR was meant to contain a $IFS-separated list of file patterns that you intended to expand. (:-b)
                      – Stéphane Chazelas
                      Aug 27 at 18:18













                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    For a basic / simplistic solution, how about creating a file first, and then, after your operation, running a find to display files newer than said file ?



                    touch /tmp/myfile
                    ( do stuff )
                    find $MY_DIR -newer /tmp/myfile


                    As @roaima points out, this only address your "which files and directories were modified as a result" requirement : it would not identify files that were removed.






                    share|improve this answer














                    For a basic / simplistic solution, how about creating a file first, and then, after your operation, running a find to display files newer than said file ?



                    touch /tmp/myfile
                    ( do stuff )
                    find $MY_DIR -newer /tmp/myfile


                    As @roaima points out, this only address your "which files and directories were modified as a result" requirement : it would not identify files that were removed.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Aug 21 at 8:37

























                    answered Aug 21 at 8:10









                    steve

                    12.9k22149




                    12.9k22149







                    • 1




                      You'd need a "before and after" to catch a tool that removed files
                      – roaima
                      Aug 21 at 8:18










                    • Note that it's zsh syntax. With bash (see tag in OP's question), you'd need find "$MY_DIR". find $MY_DIR would only make sense in bash if $MY_DIR was meant to contain a $IFS-separated list of file patterns that you intended to expand. (:-b)
                      – Stéphane Chazelas
                      Aug 27 at 18:18













                    • 1




                      You'd need a "before and after" to catch a tool that removed files
                      – roaima
                      Aug 21 at 8:18










                    • Note that it's zsh syntax. With bash (see tag in OP's question), you'd need find "$MY_DIR". find $MY_DIR would only make sense in bash if $MY_DIR was meant to contain a $IFS-separated list of file patterns that you intended to expand. (:-b)
                      – Stéphane Chazelas
                      Aug 27 at 18:18








                    1




                    1




                    You'd need a "before and after" to catch a tool that removed files
                    – roaima
                    Aug 21 at 8:18




                    You'd need a "before and after" to catch a tool that removed files
                    – roaima
                    Aug 21 at 8:18












                    Note that it's zsh syntax. With bash (see tag in OP's question), you'd need find "$MY_DIR". find $MY_DIR would only make sense in bash if $MY_DIR was meant to contain a $IFS-separated list of file patterns that you intended to expand. (:-b)
                    – Stéphane Chazelas
                    Aug 27 at 18:18





                    Note that it's zsh syntax. With bash (see tag in OP's question), you'd need find "$MY_DIR". find $MY_DIR would only make sense in bash if $MY_DIR was meant to contain a $IFS-separated list of file patterns that you intended to expand. (:-b)
                    – Stéphane Chazelas
                    Aug 27 at 18:18


















                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f463785%2fdetermine-the-files-directories-changed-as-a-result-of-running-a-command%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?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?