Determine if a file has been modifiedSee if file has been copied to USBSolaris 10 modified timedetermine...

Print the sequence

How to use an equalizer?

Would Anti-Magic Zone Affect Dragon Breath?

Modern warfare theory in a medieval setting

Why is matter-antimatter asymmetry surprising, if asymmetry can be generated by a random walk in which particles go into black holes?

Are there any privately owned large commercial airports?

Song in C major has F# note

SQL server backup message

How can I make "acts of patience" exciting?

How can I replicate this effect of the Infinity Gauntlet using official material?

How honest to be with US immigration about uncertainty about travel plans?

Transferring 9 pegs on a 9x9 grid

How much income am I getting by renting my house?

I didn't do any exit passport control when leaving Japan. What should I do?

What is joint estimation?

short story about mars colony vote influenced by French sounding song

Why is CMYK & PNG not possible?

Can I use I2C over 2m cables?

Is data science mathematically interesting?

What are the consequences for downstream actors of redistributing a work under a wider CC license than the copyright holder authorized?

Does these arithmetic means on Pythagorean triangles converge?

bash - sum numbers in a variable

What causes standard door hinges to close up to a certain amount automatically?

Can the bass be used instead of drums?



Determine if a file has been modified


See if file has been copied to USBSolaris 10 modified timedetermine user-modified filesHow does the system know when a file has been modified? In particular memory mapped files“tail -f” show old file after file has been rotatedUsing `stat` to determine filled blocksTest if File was Modified After Date in File NameRemove the latest modified fileCompare two file modification datesSet directory timestamps to most recently modified file within (recursively)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}








10

















In Linux (currently using ext4 filesystem), how can one check quickly if the contents of a file has been modified without reading any of its contents?



Is the stat command a recommended approach? I currently do



$ stat --format "%Y" hello.txt


and later I can check if the same command yields the same output. If it does, I conclude that hello.txt has not changed.



My feeling is that one wants to throw in more parameters to be even more sure. For example, would adding the file size, file name, etc, provide an even better "fingerprint" of the file?



On this topic, I recall that a TrueCrypt volume I once had was always ignored by my incremental backup program, possibly because TrueCrypt made sure to leave no meta data changes behind. I suppose it is indeed possible to change all the data returned by stat, hence it cannot be guaranteed to pick up on every possible modification of the file?










share|improve this question





























  • md5sum filename?

    – Ramesh
    Dec 29 '14 at 17:17











  • md5sum or any sort of checksum reads the contents of the file. I do not want to do that as it is way too slow for my purposes.

    – DustByte
    Dec 29 '14 at 17:19











  • ls -t will sort the contents in a directory by modification time.

    – ryekayo
    Dec 29 '14 at 17:39











  • "has been modified"? Every file has been modified, the question is when was it modified. You can use 'find' to search for a specific range of modification times.

    – Ray Andrews
    Dec 29 '14 at 17:48


















10

















In Linux (currently using ext4 filesystem), how can one check quickly if the contents of a file has been modified without reading any of its contents?



Is the stat command a recommended approach? I currently do



$ stat --format "%Y" hello.txt


and later I can check if the same command yields the same output. If it does, I conclude that hello.txt has not changed.



My feeling is that one wants to throw in more parameters to be even more sure. For example, would adding the file size, file name, etc, provide an even better "fingerprint" of the file?



On this topic, I recall that a TrueCrypt volume I once had was always ignored by my incremental backup program, possibly because TrueCrypt made sure to leave no meta data changes behind. I suppose it is indeed possible to change all the data returned by stat, hence it cannot be guaranteed to pick up on every possible modification of the file?










share|improve this question





























  • md5sum filename?

    – Ramesh
    Dec 29 '14 at 17:17











  • md5sum or any sort of checksum reads the contents of the file. I do not want to do that as it is way too slow for my purposes.

    – DustByte
    Dec 29 '14 at 17:19











  • ls -t will sort the contents in a directory by modification time.

    – ryekayo
    Dec 29 '14 at 17:39











  • "has been modified"? Every file has been modified, the question is when was it modified. You can use 'find' to search for a specific range of modification times.

    – Ray Andrews
    Dec 29 '14 at 17:48














10












10








10








In Linux (currently using ext4 filesystem), how can one check quickly if the contents of a file has been modified without reading any of its contents?



Is the stat command a recommended approach? I currently do



$ stat --format "%Y" hello.txt


and later I can check if the same command yields the same output. If it does, I conclude that hello.txt has not changed.



My feeling is that one wants to throw in more parameters to be even more sure. For example, would adding the file size, file name, etc, provide an even better "fingerprint" of the file?



On this topic, I recall that a TrueCrypt volume I once had was always ignored by my incremental backup program, possibly because TrueCrypt made sure to leave no meta data changes behind. I suppose it is indeed possible to change all the data returned by stat, hence it cannot be guaranteed to pick up on every possible modification of the file?










share|improve this question
















In Linux (currently using ext4 filesystem), how can one check quickly if the contents of a file has been modified without reading any of its contents?



Is the stat command a recommended approach? I currently do



$ stat --format "%Y" hello.txt


and later I can check if the same command yields the same output. If it does, I conclude that hello.txt has not changed.



My feeling is that one wants to throw in more parameters to be even more sure. For example, would adding the file size, file name, etc, provide an even better "fingerprint" of the file?



On this topic, I recall that a TrueCrypt volume I once had was always ignored by my incremental backup program, possibly because TrueCrypt made sure to leave no meta data changes behind. I suppose it is indeed possible to change all the data returned by stat, hence it cannot be guaranteed to pick up on every possible modification of the file?







files timestamps stat






share|improve this question















share|improve this question













share|improve this question




share|improve this question



share|improve this question








edited Dec 30 '14 at 0:30









Gilles

578k141 gold badges1193 silver badges1705 bronze badges




578k141 gold badges1193 silver badges1705 bronze badges










asked Dec 29 '14 at 17:07









DustByteDustByte

3031 gold badge5 silver badges13 bronze badges




3031 gold badge5 silver badges13 bronze badges
















  • md5sum filename?

    – Ramesh
    Dec 29 '14 at 17:17











  • md5sum or any sort of checksum reads the contents of the file. I do not want to do that as it is way too slow for my purposes.

    – DustByte
    Dec 29 '14 at 17:19











  • ls -t will sort the contents in a directory by modification time.

    – ryekayo
    Dec 29 '14 at 17:39











  • "has been modified"? Every file has been modified, the question is when was it modified. You can use 'find' to search for a specific range of modification times.

    – Ray Andrews
    Dec 29 '14 at 17:48



















  • md5sum filename?

    – Ramesh
    Dec 29 '14 at 17:17











  • md5sum or any sort of checksum reads the contents of the file. I do not want to do that as it is way too slow for my purposes.

    – DustByte
    Dec 29 '14 at 17:19











  • ls -t will sort the contents in a directory by modification time.

    – ryekayo
    Dec 29 '14 at 17:39











  • "has been modified"? Every file has been modified, the question is when was it modified. You can use 'find' to search for a specific range of modification times.

    – Ray Andrews
    Dec 29 '14 at 17:48

















md5sum filename?

– Ramesh
Dec 29 '14 at 17:17





md5sum filename?

– Ramesh
Dec 29 '14 at 17:17













md5sum or any sort of checksum reads the contents of the file. I do not want to do that as it is way too slow for my purposes.

– DustByte
Dec 29 '14 at 17:19





md5sum or any sort of checksum reads the contents of the file. I do not want to do that as it is way too slow for my purposes.

– DustByte
Dec 29 '14 at 17:19













ls -t will sort the contents in a directory by modification time.

– ryekayo
Dec 29 '14 at 17:39





ls -t will sort the contents in a directory by modification time.

– ryekayo
Dec 29 '14 at 17:39













"has been modified"? Every file has been modified, the question is when was it modified. You can use 'find' to search for a specific range of modification times.

– Ray Andrews
Dec 29 '14 at 17:48





"has been modified"? Every file has been modified, the question is when was it modified. You can use 'find' to search for a specific range of modification times.

– Ray Andrews
Dec 29 '14 at 17:48










4 Answers
4






active

oldest

votes


















5


















If you want to detect whether a file has been modified through normal means (editing it in some application, checking out a new version from a revision control systems, rebuilding it, etc.), check whether its modification time (mtime) has changed from the last check. That's what stat -c %Y reports.



The modification time can be set by the touch command. If you want to detect whether the file has changed in any way (including the use of touch, extracting an archive, etc.), check whether its inode change time (ctime) has changed from the last check. That's what stat -c %Z reports. The ctime cannot be spoofed except by the system administrator (and even then, only through indirect means: by changing the system clock, or by accessing the disk directly, bypassing the filesystem).






share|improve this answer



























  • Thanks, I gather that ctime is what I should use. It did not follow from my question that the purpose of this is to use it in my own backup script, where checksums will be computed only for new files or files that have changed. I can afford computing checksums for files that have changed just "slightly", say permissions have changed, etc. I prefer being as close as possible to actually looking at the contents of the file to determine a change.

    – DustByte
    Dec 30 '14 at 8:40



















3


















The stat command only has a resolution of a second. So if the file was modified twice in the same second you could miss a modification. Newer filesystems like ext4 provide higher resolution timestamps in nanoseconds, but some of the old tools haven't caught up yet.



Also, it's possible for other programs to set an arbitrary modification time. You can see how this can happen via the touch command.



If you're concerned about either of those two possibilities it wouldn't be a bad idea to look at the file size as well. This is what rsync does when it's looking for modified files.






share|improve this answer


































    1



















    My feeling is that one wants to throw in more parameters to be even more sure.




    What you have is the correct method. The only reason for that to fail would be if the filesystem is not updating properly -- in which case you will end up with a whole bunch of more serious problems.



    Of course, I presume someone with the right knowledge and root access to a system where the partition is accessible might be able to alter the information to make it look as if the file hasn't been changed. However, in this case they would surely have made sure to do the same with the size, etc.






    share|improve this answer


































      0


















      I make the fingerprint more detailed.



      I made a little wrapper function that generates identical output for both the MacOS/BSD and GNU versions of stat (also detects the Homebrew-installed version with a g prefix).



      init() {
      if command -v gstat > /dev/null; then
      # GNU coreutils with g prefix.
      statCmdArgs=("gstat" "--format=%n %s %b %u %g %i %h %Y %Z %W %o");
      elif ! stat --version > /dev/null 2> /dev/null; then
      # MacOS/BSD stat
      statCmdArgs=("stat" "-f" "%N %z %b %u %g %i %l %m %c %B %k");
      else
      # Assume GNU version without prefix.
      statCmdArgs=("stat" "--format=%n %s %b %u %g %i %h %Y %Z %W %o");
      fi;
      }

      getFileStatus() {
      "${statCmdArgs[@]}" "$1";
      }


      The init function gets called once during script initialization and getFileStatus can be called repeatedly without the detection overhead.






      share|improve this answer









      New contributor



      devstuff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.























        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',
        autoActivateHeartbeat: false,
        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/4.0/"u003ecc by-sa 4.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%2f176454%2fdetermine-if-a-file-has-been-modified%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown


























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        5


















        If you want to detect whether a file has been modified through normal means (editing it in some application, checking out a new version from a revision control systems, rebuilding it, etc.), check whether its modification time (mtime) has changed from the last check. That's what stat -c %Y reports.



        The modification time can be set by the touch command. If you want to detect whether the file has changed in any way (including the use of touch, extracting an archive, etc.), check whether its inode change time (ctime) has changed from the last check. That's what stat -c %Z reports. The ctime cannot be spoofed except by the system administrator (and even then, only through indirect means: by changing the system clock, or by accessing the disk directly, bypassing the filesystem).






        share|improve this answer



























        • Thanks, I gather that ctime is what I should use. It did not follow from my question that the purpose of this is to use it in my own backup script, where checksums will be computed only for new files or files that have changed. I can afford computing checksums for files that have changed just "slightly", say permissions have changed, etc. I prefer being as close as possible to actually looking at the contents of the file to determine a change.

          – DustByte
          Dec 30 '14 at 8:40
















        5


















        If you want to detect whether a file has been modified through normal means (editing it in some application, checking out a new version from a revision control systems, rebuilding it, etc.), check whether its modification time (mtime) has changed from the last check. That's what stat -c %Y reports.



        The modification time can be set by the touch command. If you want to detect whether the file has changed in any way (including the use of touch, extracting an archive, etc.), check whether its inode change time (ctime) has changed from the last check. That's what stat -c %Z reports. The ctime cannot be spoofed except by the system administrator (and even then, only through indirect means: by changing the system clock, or by accessing the disk directly, bypassing the filesystem).






        share|improve this answer



























        • Thanks, I gather that ctime is what I should use. It did not follow from my question that the purpose of this is to use it in my own backup script, where checksums will be computed only for new files or files that have changed. I can afford computing checksums for files that have changed just "slightly", say permissions have changed, etc. I prefer being as close as possible to actually looking at the contents of the file to determine a change.

          – DustByte
          Dec 30 '14 at 8:40














        5














        5










        5









        If you want to detect whether a file has been modified through normal means (editing it in some application, checking out a new version from a revision control systems, rebuilding it, etc.), check whether its modification time (mtime) has changed from the last check. That's what stat -c %Y reports.



        The modification time can be set by the touch command. If you want to detect whether the file has changed in any way (including the use of touch, extracting an archive, etc.), check whether its inode change time (ctime) has changed from the last check. That's what stat -c %Z reports. The ctime cannot be spoofed except by the system administrator (and even then, only through indirect means: by changing the system clock, or by accessing the disk directly, bypassing the filesystem).






        share|improve this answer














        If you want to detect whether a file has been modified through normal means (editing it in some application, checking out a new version from a revision control systems, rebuilding it, etc.), check whether its modification time (mtime) has changed from the last check. That's what stat -c %Y reports.



        The modification time can be set by the touch command. If you want to detect whether the file has changed in any way (including the use of touch, extracting an archive, etc.), check whether its inode change time (ctime) has changed from the last check. That's what stat -c %Z reports. The ctime cannot be spoofed except by the system administrator (and even then, only through indirect means: by changing the system clock, or by accessing the disk directly, bypassing the filesystem).







        share|improve this answer













        share|improve this answer




        share|improve this answer



        share|improve this answer










        answered Dec 30 '14 at 0:30









        GillesGilles

        578k141 gold badges1193 silver badges1705 bronze badges




        578k141 gold badges1193 silver badges1705 bronze badges
















        • Thanks, I gather that ctime is what I should use. It did not follow from my question that the purpose of this is to use it in my own backup script, where checksums will be computed only for new files or files that have changed. I can afford computing checksums for files that have changed just "slightly", say permissions have changed, etc. I prefer being as close as possible to actually looking at the contents of the file to determine a change.

          – DustByte
          Dec 30 '14 at 8:40



















        • Thanks, I gather that ctime is what I should use. It did not follow from my question that the purpose of this is to use it in my own backup script, where checksums will be computed only for new files or files that have changed. I can afford computing checksums for files that have changed just "slightly", say permissions have changed, etc. I prefer being as close as possible to actually looking at the contents of the file to determine a change.

          – DustByte
          Dec 30 '14 at 8:40

















        Thanks, I gather that ctime is what I should use. It did not follow from my question that the purpose of this is to use it in my own backup script, where checksums will be computed only for new files or files that have changed. I can afford computing checksums for files that have changed just "slightly", say permissions have changed, etc. I prefer being as close as possible to actually looking at the contents of the file to determine a change.

        – DustByte
        Dec 30 '14 at 8:40





        Thanks, I gather that ctime is what I should use. It did not follow from my question that the purpose of this is to use it in my own backup script, where checksums will be computed only for new files or files that have changed. I can afford computing checksums for files that have changed just "slightly", say permissions have changed, etc. I prefer being as close as possible to actually looking at the contents of the file to determine a change.

        – DustByte
        Dec 30 '14 at 8:40













        3


















        The stat command only has a resolution of a second. So if the file was modified twice in the same second you could miss a modification. Newer filesystems like ext4 provide higher resolution timestamps in nanoseconds, but some of the old tools haven't caught up yet.



        Also, it's possible for other programs to set an arbitrary modification time. You can see how this can happen via the touch command.



        If you're concerned about either of those two possibilities it wouldn't be a bad idea to look at the file size as well. This is what rsync does when it's looking for modified files.






        share|improve this answer































          3


















          The stat command only has a resolution of a second. So if the file was modified twice in the same second you could miss a modification. Newer filesystems like ext4 provide higher resolution timestamps in nanoseconds, but some of the old tools haven't caught up yet.



          Also, it's possible for other programs to set an arbitrary modification time. You can see how this can happen via the touch command.



          If you're concerned about either of those two possibilities it wouldn't be a bad idea to look at the file size as well. This is what rsync does when it's looking for modified files.






          share|improve this answer





























            3














            3










            3









            The stat command only has a resolution of a second. So if the file was modified twice in the same second you could miss a modification. Newer filesystems like ext4 provide higher resolution timestamps in nanoseconds, but some of the old tools haven't caught up yet.



            Also, it's possible for other programs to set an arbitrary modification time. You can see how this can happen via the touch command.



            If you're concerned about either of those two possibilities it wouldn't be a bad idea to look at the file size as well. This is what rsync does when it's looking for modified files.






            share|improve this answer














            The stat command only has a resolution of a second. So if the file was modified twice in the same second you could miss a modification. Newer filesystems like ext4 provide higher resolution timestamps in nanoseconds, but some of the old tools haven't caught up yet.



            Also, it's possible for other programs to set an arbitrary modification time. You can see how this can happen via the touch command.



            If you're concerned about either of those two possibilities it wouldn't be a bad idea to look at the file size as well. This is what rsync does when it's looking for modified files.







            share|improve this answer













            share|improve this answer




            share|improve this answer



            share|improve this answer










            answered Dec 29 '14 at 18:42









            Steve SetherSteve Sether

            1313 bronze badges




            1313 bronze badges


























                1



















                My feeling is that one wants to throw in more parameters to be even more sure.




                What you have is the correct method. The only reason for that to fail would be if the filesystem is not updating properly -- in which case you will end up with a whole bunch of more serious problems.



                Of course, I presume someone with the right knowledge and root access to a system where the partition is accessible might be able to alter the information to make it look as if the file hasn't been changed. However, in this case they would surely have made sure to do the same with the size, etc.






                share|improve this answer































                  1



















                  My feeling is that one wants to throw in more parameters to be even more sure.




                  What you have is the correct method. The only reason for that to fail would be if the filesystem is not updating properly -- in which case you will end up with a whole bunch of more serious problems.



                  Of course, I presume someone with the right knowledge and root access to a system where the partition is accessible might be able to alter the information to make it look as if the file hasn't been changed. However, in this case they would surely have made sure to do the same with the size, etc.






                  share|improve this answer





























                    1














                    1










                    1










                    My feeling is that one wants to throw in more parameters to be even more sure.




                    What you have is the correct method. The only reason for that to fail would be if the filesystem is not updating properly -- in which case you will end up with a whole bunch of more serious problems.



                    Of course, I presume someone with the right knowledge and root access to a system where the partition is accessible might be able to alter the information to make it look as if the file hasn't been changed. However, in this case they would surely have made sure to do the same with the size, etc.






                    share|improve this answer















                    My feeling is that one wants to throw in more parameters to be even more sure.




                    What you have is the correct method. The only reason for that to fail would be if the filesystem is not updating properly -- in which case you will end up with a whole bunch of more serious problems.



                    Of course, I presume someone with the right knowledge and root access to a system where the partition is accessible might be able to alter the information to make it look as if the file hasn't been changed. However, in this case they would surely have made sure to do the same with the size, etc.







                    share|improve this answer













                    share|improve this answer




                    share|improve this answer



                    share|improve this answer










                    answered Dec 29 '14 at 17:36









                    goldilocksgoldilocks

                    66.2k19 gold badges166 silver badges219 bronze badges




                    66.2k19 gold badges166 silver badges219 bronze badges


























                        0


















                        I make the fingerprint more detailed.



                        I made a little wrapper function that generates identical output for both the MacOS/BSD and GNU versions of stat (also detects the Homebrew-installed version with a g prefix).



                        init() {
                        if command -v gstat > /dev/null; then
                        # GNU coreutils with g prefix.
                        statCmdArgs=("gstat" "--format=%n %s %b %u %g %i %h %Y %Z %W %o");
                        elif ! stat --version > /dev/null 2> /dev/null; then
                        # MacOS/BSD stat
                        statCmdArgs=("stat" "-f" "%N %z %b %u %g %i %l %m %c %B %k");
                        else
                        # Assume GNU version without prefix.
                        statCmdArgs=("stat" "--format=%n %s %b %u %g %i %h %Y %Z %W %o");
                        fi;
                        }

                        getFileStatus() {
                        "${statCmdArgs[@]}" "$1";
                        }


                        The init function gets called once during script initialization and getFileStatus can be called repeatedly without the detection overhead.






                        share|improve this answer









                        New contributor



                        devstuff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.


























                          0


















                          I make the fingerprint more detailed.



                          I made a little wrapper function that generates identical output for both the MacOS/BSD and GNU versions of stat (also detects the Homebrew-installed version with a g prefix).



                          init() {
                          if command -v gstat > /dev/null; then
                          # GNU coreutils with g prefix.
                          statCmdArgs=("gstat" "--format=%n %s %b %u %g %i %h %Y %Z %W %o");
                          elif ! stat --version > /dev/null 2> /dev/null; then
                          # MacOS/BSD stat
                          statCmdArgs=("stat" "-f" "%N %z %b %u %g %i %l %m %c %B %k");
                          else
                          # Assume GNU version without prefix.
                          statCmdArgs=("stat" "--format=%n %s %b %u %g %i %h %Y %Z %W %o");
                          fi;
                          }

                          getFileStatus() {
                          "${statCmdArgs[@]}" "$1";
                          }


                          The init function gets called once during script initialization and getFileStatus can be called repeatedly without the detection overhead.






                          share|improve this answer









                          New contributor



                          devstuff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.
























                            0














                            0










                            0









                            I make the fingerprint more detailed.



                            I made a little wrapper function that generates identical output for both the MacOS/BSD and GNU versions of stat (also detects the Homebrew-installed version with a g prefix).



                            init() {
                            if command -v gstat > /dev/null; then
                            # GNU coreutils with g prefix.
                            statCmdArgs=("gstat" "--format=%n %s %b %u %g %i %h %Y %Z %W %o");
                            elif ! stat --version > /dev/null 2> /dev/null; then
                            # MacOS/BSD stat
                            statCmdArgs=("stat" "-f" "%N %z %b %u %g %i %l %m %c %B %k");
                            else
                            # Assume GNU version without prefix.
                            statCmdArgs=("stat" "--format=%n %s %b %u %g %i %h %Y %Z %W %o");
                            fi;
                            }

                            getFileStatus() {
                            "${statCmdArgs[@]}" "$1";
                            }


                            The init function gets called once during script initialization and getFileStatus can be called repeatedly without the detection overhead.






                            share|improve this answer









                            New contributor



                            devstuff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            I make the fingerprint more detailed.



                            I made a little wrapper function that generates identical output for both the MacOS/BSD and GNU versions of stat (also detects the Homebrew-installed version with a g prefix).



                            init() {
                            if command -v gstat > /dev/null; then
                            # GNU coreutils with g prefix.
                            statCmdArgs=("gstat" "--format=%n %s %b %u %g %i %h %Y %Z %W %o");
                            elif ! stat --version > /dev/null 2> /dev/null; then
                            # MacOS/BSD stat
                            statCmdArgs=("stat" "-f" "%N %z %b %u %g %i %l %m %c %B %k");
                            else
                            # Assume GNU version without prefix.
                            statCmdArgs=("stat" "--format=%n %s %b %u %g %i %h %Y %Z %W %o");
                            fi;
                            }

                            getFileStatus() {
                            "${statCmdArgs[@]}" "$1";
                            }


                            The init function gets called once during script initialization and getFileStatus can be called repeatedly without the detection overhead.







                            share|improve this answer









                            New contributor



                            devstuff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.








                            share|improve this answer




                            share|improve this answer



                            share|improve this answer






                            New contributor



                            devstuff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.








                            answered 30 mins ago









                            devstuffdevstuff

                            1012 bronze badges




                            1012 bronze badges




                            New contributor



                            devstuff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.




                            New contributor




                            devstuff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.




































                                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.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f176454%2fdetermine-if-a-file-has-been-modified%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









                                Popular posts from this blog

                                Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                                Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                                Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...