How to list files that were changed in a certain range of time?












34















How can I list recursively all files that were changed between 22.12.2011 and 24.12.2011?










share|improve this question




















  • 6





    If you mean 'last changed', you have a chance at a solution. If a file was modified on 26.12.2011, you cannot tell if it was also modified during your given range. (Unless you have a very exotic file system.)

    – William Pursell
    Jan 17 '12 at 2:07
















34















How can I list recursively all files that were changed between 22.12.2011 and 24.12.2011?










share|improve this question




















  • 6





    If you mean 'last changed', you have a chance at a solution. If a file was modified on 26.12.2011, you cannot tell if it was also modified during your given range. (Unless you have a very exotic file system.)

    – William Pursell
    Jan 17 '12 at 2:07














34












34








34


14






How can I list recursively all files that were changed between 22.12.2011 and 24.12.2011?










share|improve this question
















How can I list recursively all files that were changed between 22.12.2011 and 24.12.2011?







files recursive timestamps






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 17 '12 at 7:57







user13742

















asked Jan 16 '12 at 22:03









clampclamp

59841226




59841226








  • 6





    If you mean 'last changed', you have a chance at a solution. If a file was modified on 26.12.2011, you cannot tell if it was also modified during your given range. (Unless you have a very exotic file system.)

    – William Pursell
    Jan 17 '12 at 2:07














  • 6





    If you mean 'last changed', you have a chance at a solution. If a file was modified on 26.12.2011, you cannot tell if it was also modified during your given range. (Unless you have a very exotic file system.)

    – William Pursell
    Jan 17 '12 at 2:07








6




6





If you mean 'last changed', you have a chance at a solution. If a file was modified on 26.12.2011, you cannot tell if it was also modified during your given range. (Unless you have a very exotic file system.)

– William Pursell
Jan 17 '12 at 2:07





If you mean 'last changed', you have a chance at a solution. If a file was modified on 26.12.2011, you cannot tell if it was also modified during your given range. (Unless you have a very exotic file system.)

– William Pursell
Jan 17 '12 at 2:07










6 Answers
6






active

oldest

votes


















23














Generally speaking, when you're looking for files in a directory and its subdirectories recursively, use find.



The easiest way to specify a date range with find is to create files at the boundaries of the range and use the -newer predicate.



touch -t 201112220000 start
touch -t 201112240000 stop
find . -newer start ! -newer stop





share|improve this answer
























  • why negating the output of the first -newer is needed here?

    – Alexander Cska
    Dec 16 '18 at 15:42











  • @AlexanderCska The first -newer isn't negated, the second one is. “Find files that are newer than start but not newer than stop”.

    – Gilles
    Dec 16 '18 at 15:52











  • Ok negation works on the command after. What would happen if no negation was present?

    – Alexander Cska
    Dec 16 '18 at 17:14













  • @AlexanderCska Then you'd get the files that are newer than both start and stop.

    – Gilles
    Dec 16 '18 at 18:24



















32














Using Gilles' solution and after reading the man find(1) again I found a more simple solution. The best option is the -newerXY. The m and t flags can be used.



m   The modification time of the file reference
t reference is interpreted directly as a time


So the solution is



find . -type f -newermt 20111222 ! -newermt 20111225


The lower bound in inclusive, and upper bound is exclusive, so I added 1 day to it! And it is recursive.
It works well on find v4.5.9.






share|improve this answer


























  • Cool trick, thanks! That helped me with finding a recent file containing a certain keyword in a directory with thousands of files: find -newermt 20150212 ! -newermt 20150213 | xargs grep 'keyword' -m 50 -l (-m 50 = search in first 50 lines).

    – Rob W
    Feb 13 '15 at 10:20











  • @RobW: Actually you can spare the pipe and xargs using -exec ... + in find(1), like: find -newermt 20150212 ! -newermt 20150213 -exec grep keyword -m 50 -l {} +. This does the same, but cheaper.

    – TrueY
    Feb 13 '15 at 10:27













  • I had to enclose the timestamps with double quote (I'm on Ubuntu Xenial with find 4.7.0-git).

    – IsaacS
    Dec 27 '16 at 21:13



















12














In addition to the answers already given, note that you can directly specify your dates:



find -type f -newermt "2011-12-22" ! -newermt "2011-12-24"


or



find -type f -newermt "2011-12-22 00:00:00" ! -newermt "2011-12-24 13:23:00"


if you additionally want to specify the time.






share|improve this answer































    6














    Assuming you don't need precision to the seconds, this should work.



    find . -type f -mmin -$(((`date +%s`-`date -d 20111222 +"%s"`)/60)) ! -mmin +$(((`date +%s`-`date -d 20111224 +"%s"`)/60))


    EDIT: Changed cmin to mmin after @Eelvex's comment.
    EDIT: '!' missing






    share|improve this answer


























    • hm doesnt seem to work. are you sure it recursively walks through the subdirectories?

      – clamp
      Jan 16 '12 at 22:29











    • Yes, it works on me. Do you really have files modified in that time range? Try it with different time ranges.

      – onur güngör
      Jan 16 '12 at 22:32








    • 6





      -cmin is "status change", -mmin is "data change". You probably want -mmin

      – Eelvex
      Jan 17 '12 at 0:01



















    3














    find can take an ISO formatted datetime, so for a server on UTC for instance, you could specify an offset of a number of hours from wherever you are. This also takes care of having to add a day since you're comparing time too:



    find -type f -newermt 20111224T0800 ! -newermt 20111225T0800





    share|improve this answer

































      0














      Please note that the question marked as duplicate, and therefore is restricted from answering it directly, is why I'm posting into here. This answer is for answering the question "need to move files to different folder based on the creation date [duplicate]"



      The answers are reasonable but there were some limitations with a purely find command. I wrote this shell script to go through a directory with so many files in it the filesystem was gagging on the metadata trying to perform an ls. Additionally some *nix systems will barf a too many arguments error with running ls.



      The find command is very powerful and I started with the methods that are listed but I had so many years of data throughout that directory that I had to pass over all the files repeatedly. This produces a lot of needless passed over each file. I tried doing one screen per year and running multiple finds but this resulted in a lot of errors from each find and files would go missing when one of the finds moved it.



      My shell script moves a file to the destination directory, with a 4 digit year and a 2 digit month. It can easily be expanded to a 2 digit day by uncommenting a couple lines and commenting out their counterparts. I believe it's more efficient because it was perform the moves in one pass of find so multiple find commands and passes over the directory are unneeded.



      #!/bin/bash
      #We want to exit if there is no argument submitted
      if [ -z "$1" ]
      then
      echo no input file
      exit
      fi

      #destDir should be set to where ever you want the files to go
      destDir="/home/user/destination"

      #Get the month and year of modification time
      #--format %y returns the modification date in the format:
      # 2016-04-26 12:40:48.000000000 -0400
      #We then take the first column, split by a white space with awk
      date=`stat "$1" --format %y | awk '{ print $1 }'`

      #This sets the year variable to the first column split on a - with awk
      year=`echo $date | awk -F- '{print $1 }'`
      #This sets the month variable to the second column split on a - with awk
      month=`echo $date | awk -F- '{print $2 }'`
      #This sets the day variable to the third column split on a - with awk
      #This is commented out because I didn't want to add day to mine
      #day=`echo $date | awk -F- '{print $3 }'`

      #Here we check if the destination directory with year and month exist
      #If not then we want to create it with -p so the parent is created if
      # it doesn't already exist
      if [ ! -d $destDir/$year/$month ]
      then
      mkdir -p $destDir/$year/$month || exit
      fi

      #This is the same as above but utilizes the day subdirectory
      #Uncommented this out and comment out the similar code above
      #if [ ! -d $destDir/$year/$month/$day ]
      #then
      # mkdir -p $destDir/$year/$month$day || exit
      #fi

      #Echoing out what we're doing
      #The uncommented is for just year/month and the commented line includes day
      #Comment the first and uncomment the second if you need day
      echo Moving $1 to $destDir/$year/$month
      #echo Moving $1 to $destDir/$year/$month/$day

      #Move the file to the newly created directory
      #The uncommented is for just year/month and the commented line includes day
      #Comment the first and uncomment the second if you need day
      mv "$1" $destDir/$year/$month
      #mv "$1" $destDir/$year/$month/$day


      Once saved and made executable you may call this script with find like the following.



      find /path/to/directory -type f -exec /home/username/move_files.sh {} ;


      You don't need to worry about setting the newermt option for find as all find is providing is a single execution per file found and the script makes all the decisions.



      Keep in mind that if you don't select -type f it will move directories around and that will likely cause issues. You could also use -type d if you're looking to move just directories. Not setting the type will almost certainly produce unwanted behaviour.



      Remember that this script was tailoured to my needs. You may want to simply use my construct as inspiration for a better suited for your needs script. Thank you!



      Considerations: The efficiency of the command can be GREATLY improved by allowing an unlimited number of arguments to pass through the script. This is actually relatively easy if you pass over the $@ variable. Extending the functionality of this would allow us to use find's -exec + function or leverage xargs, for example. I may quickly implement that and improve my own answer but this is a start.



      Since this was a one-shot script session there are probably many improvements that can be made. Good luck!






      share|improve this answer










      New contributor




      Vex Mage 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/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%2f29245%2fhow-to-list-files-that-were-changed-in-a-certain-range-of-time%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        6 Answers
        6






        active

        oldest

        votes








        6 Answers
        6






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        23














        Generally speaking, when you're looking for files in a directory and its subdirectories recursively, use find.



        The easiest way to specify a date range with find is to create files at the boundaries of the range and use the -newer predicate.



        touch -t 201112220000 start
        touch -t 201112240000 stop
        find . -newer start ! -newer stop





        share|improve this answer
























        • why negating the output of the first -newer is needed here?

          – Alexander Cska
          Dec 16 '18 at 15:42











        • @AlexanderCska The first -newer isn't negated, the second one is. “Find files that are newer than start but not newer than stop”.

          – Gilles
          Dec 16 '18 at 15:52











        • Ok negation works on the command after. What would happen if no negation was present?

          – Alexander Cska
          Dec 16 '18 at 17:14













        • @AlexanderCska Then you'd get the files that are newer than both start and stop.

          – Gilles
          Dec 16 '18 at 18:24
















        23














        Generally speaking, when you're looking for files in a directory and its subdirectories recursively, use find.



        The easiest way to specify a date range with find is to create files at the boundaries of the range and use the -newer predicate.



        touch -t 201112220000 start
        touch -t 201112240000 stop
        find . -newer start ! -newer stop





        share|improve this answer
























        • why negating the output of the first -newer is needed here?

          – Alexander Cska
          Dec 16 '18 at 15:42











        • @AlexanderCska The first -newer isn't negated, the second one is. “Find files that are newer than start but not newer than stop”.

          – Gilles
          Dec 16 '18 at 15:52











        • Ok negation works on the command after. What would happen if no negation was present?

          – Alexander Cska
          Dec 16 '18 at 17:14













        • @AlexanderCska Then you'd get the files that are newer than both start and stop.

          – Gilles
          Dec 16 '18 at 18:24














        23












        23








        23







        Generally speaking, when you're looking for files in a directory and its subdirectories recursively, use find.



        The easiest way to specify a date range with find is to create files at the boundaries of the range and use the -newer predicate.



        touch -t 201112220000 start
        touch -t 201112240000 stop
        find . -newer start ! -newer stop





        share|improve this answer













        Generally speaking, when you're looking for files in a directory and its subdirectories recursively, use find.



        The easiest way to specify a date range with find is to create files at the boundaries of the range and use the -newer predicate.



        touch -t 201112220000 start
        touch -t 201112240000 stop
        find . -newer start ! -newer stop






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 17 '12 at 0:11









        GillesGilles

        542k12810991616




        542k12810991616













        • why negating the output of the first -newer is needed here?

          – Alexander Cska
          Dec 16 '18 at 15:42











        • @AlexanderCska The first -newer isn't negated, the second one is. “Find files that are newer than start but not newer than stop”.

          – Gilles
          Dec 16 '18 at 15:52











        • Ok negation works on the command after. What would happen if no negation was present?

          – Alexander Cska
          Dec 16 '18 at 17:14













        • @AlexanderCska Then you'd get the files that are newer than both start and stop.

          – Gilles
          Dec 16 '18 at 18:24



















        • why negating the output of the first -newer is needed here?

          – Alexander Cska
          Dec 16 '18 at 15:42











        • @AlexanderCska The first -newer isn't negated, the second one is. “Find files that are newer than start but not newer than stop”.

          – Gilles
          Dec 16 '18 at 15:52











        • Ok negation works on the command after. What would happen if no negation was present?

          – Alexander Cska
          Dec 16 '18 at 17:14













        • @AlexanderCska Then you'd get the files that are newer than both start and stop.

          – Gilles
          Dec 16 '18 at 18:24

















        why negating the output of the first -newer is needed here?

        – Alexander Cska
        Dec 16 '18 at 15:42





        why negating the output of the first -newer is needed here?

        – Alexander Cska
        Dec 16 '18 at 15:42













        @AlexanderCska The first -newer isn't negated, the second one is. “Find files that are newer than start but not newer than stop”.

        – Gilles
        Dec 16 '18 at 15:52





        @AlexanderCska The first -newer isn't negated, the second one is. “Find files that are newer than start but not newer than stop”.

        – Gilles
        Dec 16 '18 at 15:52













        Ok negation works on the command after. What would happen if no negation was present?

        – Alexander Cska
        Dec 16 '18 at 17:14







        Ok negation works on the command after. What would happen if no negation was present?

        – Alexander Cska
        Dec 16 '18 at 17:14















        @AlexanderCska Then you'd get the files that are newer than both start and stop.

        – Gilles
        Dec 16 '18 at 18:24





        @AlexanderCska Then you'd get the files that are newer than both start and stop.

        – Gilles
        Dec 16 '18 at 18:24













        32














        Using Gilles' solution and after reading the man find(1) again I found a more simple solution. The best option is the -newerXY. The m and t flags can be used.



        m   The modification time of the file reference
        t reference is interpreted directly as a time


        So the solution is



        find . -type f -newermt 20111222 ! -newermt 20111225


        The lower bound in inclusive, and upper bound is exclusive, so I added 1 day to it! And it is recursive.
        It works well on find v4.5.9.






        share|improve this answer


























        • Cool trick, thanks! That helped me with finding a recent file containing a certain keyword in a directory with thousands of files: find -newermt 20150212 ! -newermt 20150213 | xargs grep 'keyword' -m 50 -l (-m 50 = search in first 50 lines).

          – Rob W
          Feb 13 '15 at 10:20











        • @RobW: Actually you can spare the pipe and xargs using -exec ... + in find(1), like: find -newermt 20150212 ! -newermt 20150213 -exec grep keyword -m 50 -l {} +. This does the same, but cheaper.

          – TrueY
          Feb 13 '15 at 10:27













        • I had to enclose the timestamps with double quote (I'm on Ubuntu Xenial with find 4.7.0-git).

          – IsaacS
          Dec 27 '16 at 21:13
















        32














        Using Gilles' solution and after reading the man find(1) again I found a more simple solution. The best option is the -newerXY. The m and t flags can be used.



        m   The modification time of the file reference
        t reference is interpreted directly as a time


        So the solution is



        find . -type f -newermt 20111222 ! -newermt 20111225


        The lower bound in inclusive, and upper bound is exclusive, so I added 1 day to it! And it is recursive.
        It works well on find v4.5.9.






        share|improve this answer


























        • Cool trick, thanks! That helped me with finding a recent file containing a certain keyword in a directory with thousands of files: find -newermt 20150212 ! -newermt 20150213 | xargs grep 'keyword' -m 50 -l (-m 50 = search in first 50 lines).

          – Rob W
          Feb 13 '15 at 10:20











        • @RobW: Actually you can spare the pipe and xargs using -exec ... + in find(1), like: find -newermt 20150212 ! -newermt 20150213 -exec grep keyword -m 50 -l {} +. This does the same, but cheaper.

          – TrueY
          Feb 13 '15 at 10:27













        • I had to enclose the timestamps with double quote (I'm on Ubuntu Xenial with find 4.7.0-git).

          – IsaacS
          Dec 27 '16 at 21:13














        32












        32








        32







        Using Gilles' solution and after reading the man find(1) again I found a more simple solution. The best option is the -newerXY. The m and t flags can be used.



        m   The modification time of the file reference
        t reference is interpreted directly as a time


        So the solution is



        find . -type f -newermt 20111222 ! -newermt 20111225


        The lower bound in inclusive, and upper bound is exclusive, so I added 1 day to it! And it is recursive.
        It works well on find v4.5.9.






        share|improve this answer















        Using Gilles' solution and after reading the man find(1) again I found a more simple solution. The best option is the -newerXY. The m and t flags can be used.



        m   The modification time of the file reference
        t reference is interpreted directly as a time


        So the solution is



        find . -type f -newermt 20111222 ! -newermt 20111225


        The lower bound in inclusive, and upper bound is exclusive, so I added 1 day to it! And it is recursive.
        It works well on find v4.5.9.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Aug 18 '15 at 13:23









        dr01

        16.2k115074




        16.2k115074










        answered Mar 28 '13 at 8:58









        TrueYTrueY

        46358




        46358













        • Cool trick, thanks! That helped me with finding a recent file containing a certain keyword in a directory with thousands of files: find -newermt 20150212 ! -newermt 20150213 | xargs grep 'keyword' -m 50 -l (-m 50 = search in first 50 lines).

          – Rob W
          Feb 13 '15 at 10:20











        • @RobW: Actually you can spare the pipe and xargs using -exec ... + in find(1), like: find -newermt 20150212 ! -newermt 20150213 -exec grep keyword -m 50 -l {} +. This does the same, but cheaper.

          – TrueY
          Feb 13 '15 at 10:27













        • I had to enclose the timestamps with double quote (I'm on Ubuntu Xenial with find 4.7.0-git).

          – IsaacS
          Dec 27 '16 at 21:13



















        • Cool trick, thanks! That helped me with finding a recent file containing a certain keyword in a directory with thousands of files: find -newermt 20150212 ! -newermt 20150213 | xargs grep 'keyword' -m 50 -l (-m 50 = search in first 50 lines).

          – Rob W
          Feb 13 '15 at 10:20











        • @RobW: Actually you can spare the pipe and xargs using -exec ... + in find(1), like: find -newermt 20150212 ! -newermt 20150213 -exec grep keyword -m 50 -l {} +. This does the same, but cheaper.

          – TrueY
          Feb 13 '15 at 10:27













        • I had to enclose the timestamps with double quote (I'm on Ubuntu Xenial with find 4.7.0-git).

          – IsaacS
          Dec 27 '16 at 21:13

















        Cool trick, thanks! That helped me with finding a recent file containing a certain keyword in a directory with thousands of files: find -newermt 20150212 ! -newermt 20150213 | xargs grep 'keyword' -m 50 -l (-m 50 = search in first 50 lines).

        – Rob W
        Feb 13 '15 at 10:20





        Cool trick, thanks! That helped me with finding a recent file containing a certain keyword in a directory with thousands of files: find -newermt 20150212 ! -newermt 20150213 | xargs grep 'keyword' -m 50 -l (-m 50 = search in first 50 lines).

        – Rob W
        Feb 13 '15 at 10:20













        @RobW: Actually you can spare the pipe and xargs using -exec ... + in find(1), like: find -newermt 20150212 ! -newermt 20150213 -exec grep keyword -m 50 -l {} +. This does the same, but cheaper.

        – TrueY
        Feb 13 '15 at 10:27







        @RobW: Actually you can spare the pipe and xargs using -exec ... + in find(1), like: find -newermt 20150212 ! -newermt 20150213 -exec grep keyword -m 50 -l {} +. This does the same, but cheaper.

        – TrueY
        Feb 13 '15 at 10:27















        I had to enclose the timestamps with double quote (I'm on Ubuntu Xenial with find 4.7.0-git).

        – IsaacS
        Dec 27 '16 at 21:13





        I had to enclose the timestamps with double quote (I'm on Ubuntu Xenial with find 4.7.0-git).

        – IsaacS
        Dec 27 '16 at 21:13











        12














        In addition to the answers already given, note that you can directly specify your dates:



        find -type f -newermt "2011-12-22" ! -newermt "2011-12-24"


        or



        find -type f -newermt "2011-12-22 00:00:00" ! -newermt "2011-12-24 13:23:00"


        if you additionally want to specify the time.






        share|improve this answer




























          12














          In addition to the answers already given, note that you can directly specify your dates:



          find -type f -newermt "2011-12-22" ! -newermt "2011-12-24"


          or



          find -type f -newermt "2011-12-22 00:00:00" ! -newermt "2011-12-24 13:23:00"


          if you additionally want to specify the time.






          share|improve this answer


























            12












            12








            12







            In addition to the answers already given, note that you can directly specify your dates:



            find -type f -newermt "2011-12-22" ! -newermt "2011-12-24"


            or



            find -type f -newermt "2011-12-22 00:00:00" ! -newermt "2011-12-24 13:23:00"


            if you additionally want to specify the time.






            share|improve this answer













            In addition to the answers already given, note that you can directly specify your dates:



            find -type f -newermt "2011-12-22" ! -newermt "2011-12-24"


            or



            find -type f -newermt "2011-12-22 00:00:00" ! -newermt "2011-12-24 13:23:00"


            if you additionally want to specify the time.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered May 11 '15 at 18:42









            studentstudent

            7,2351766129




            7,2351766129























                6














                Assuming you don't need precision to the seconds, this should work.



                find . -type f -mmin -$(((`date +%s`-`date -d 20111222 +"%s"`)/60)) ! -mmin +$(((`date +%s`-`date -d 20111224 +"%s"`)/60))


                EDIT: Changed cmin to mmin after @Eelvex's comment.
                EDIT: '!' missing






                share|improve this answer


























                • hm doesnt seem to work. are you sure it recursively walks through the subdirectories?

                  – clamp
                  Jan 16 '12 at 22:29











                • Yes, it works on me. Do you really have files modified in that time range? Try it with different time ranges.

                  – onur güngör
                  Jan 16 '12 at 22:32








                • 6





                  -cmin is "status change", -mmin is "data change". You probably want -mmin

                  – Eelvex
                  Jan 17 '12 at 0:01
















                6














                Assuming you don't need precision to the seconds, this should work.



                find . -type f -mmin -$(((`date +%s`-`date -d 20111222 +"%s"`)/60)) ! -mmin +$(((`date +%s`-`date -d 20111224 +"%s"`)/60))


                EDIT: Changed cmin to mmin after @Eelvex's comment.
                EDIT: '!' missing






                share|improve this answer


























                • hm doesnt seem to work. are you sure it recursively walks through the subdirectories?

                  – clamp
                  Jan 16 '12 at 22:29











                • Yes, it works on me. Do you really have files modified in that time range? Try it with different time ranges.

                  – onur güngör
                  Jan 16 '12 at 22:32








                • 6





                  -cmin is "status change", -mmin is "data change". You probably want -mmin

                  – Eelvex
                  Jan 17 '12 at 0:01














                6












                6








                6







                Assuming you don't need precision to the seconds, this should work.



                find . -type f -mmin -$(((`date +%s`-`date -d 20111222 +"%s"`)/60)) ! -mmin +$(((`date +%s`-`date -d 20111224 +"%s"`)/60))


                EDIT: Changed cmin to mmin after @Eelvex's comment.
                EDIT: '!' missing






                share|improve this answer















                Assuming you don't need precision to the seconds, this should work.



                find . -type f -mmin -$(((`date +%s`-`date -d 20111222 +"%s"`)/60)) ! -mmin +$(((`date +%s`-`date -d 20111224 +"%s"`)/60))


                EDIT: Changed cmin to mmin after @Eelvex's comment.
                EDIT: '!' missing







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 28 '13 at 10:46









                TrueY

                46358




                46358










                answered Jan 16 '12 at 22:25









                onur güngöronur güngör

                784513




                784513













                • hm doesnt seem to work. are you sure it recursively walks through the subdirectories?

                  – clamp
                  Jan 16 '12 at 22:29











                • Yes, it works on me. Do you really have files modified in that time range? Try it with different time ranges.

                  – onur güngör
                  Jan 16 '12 at 22:32








                • 6





                  -cmin is "status change", -mmin is "data change". You probably want -mmin

                  – Eelvex
                  Jan 17 '12 at 0:01



















                • hm doesnt seem to work. are you sure it recursively walks through the subdirectories?

                  – clamp
                  Jan 16 '12 at 22:29











                • Yes, it works on me. Do you really have files modified in that time range? Try it with different time ranges.

                  – onur güngör
                  Jan 16 '12 at 22:32








                • 6





                  -cmin is "status change", -mmin is "data change". You probably want -mmin

                  – Eelvex
                  Jan 17 '12 at 0:01

















                hm doesnt seem to work. are you sure it recursively walks through the subdirectories?

                – clamp
                Jan 16 '12 at 22:29





                hm doesnt seem to work. are you sure it recursively walks through the subdirectories?

                – clamp
                Jan 16 '12 at 22:29













                Yes, it works on me. Do you really have files modified in that time range? Try it with different time ranges.

                – onur güngör
                Jan 16 '12 at 22:32







                Yes, it works on me. Do you really have files modified in that time range? Try it with different time ranges.

                – onur güngör
                Jan 16 '12 at 22:32






                6




                6





                -cmin is "status change", -mmin is "data change". You probably want -mmin

                – Eelvex
                Jan 17 '12 at 0:01





                -cmin is "status change", -mmin is "data change". You probably want -mmin

                – Eelvex
                Jan 17 '12 at 0:01











                3














                find can take an ISO formatted datetime, so for a server on UTC for instance, you could specify an offset of a number of hours from wherever you are. This also takes care of having to add a day since you're comparing time too:



                find -type f -newermt 20111224T0800 ! -newermt 20111225T0800





                share|improve this answer






























                  3














                  find can take an ISO formatted datetime, so for a server on UTC for instance, you could specify an offset of a number of hours from wherever you are. This also takes care of having to add a day since you're comparing time too:



                  find -type f -newermt 20111224T0800 ! -newermt 20111225T0800





                  share|improve this answer




























                    3












                    3








                    3







                    find can take an ISO formatted datetime, so for a server on UTC for instance, you could specify an offset of a number of hours from wherever you are. This also takes care of having to add a day since you're comparing time too:



                    find -type f -newermt 20111224T0800 ! -newermt 20111225T0800





                    share|improve this answer















                    find can take an ISO formatted datetime, so for a server on UTC for instance, you could specify an offset of a number of hours from wherever you are. This also takes care of having to add a day since you're comparing time too:



                    find -type f -newermt 20111224T0800 ! -newermt 20111225T0800






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 9 '15 at 19:19









                    HalosGhost

                    3,76392236




                    3,76392236










                    answered Mar 9 '15 at 18:58









                    Alex YoungAlex Young

                    1311




                    1311























                        0














                        Please note that the question marked as duplicate, and therefore is restricted from answering it directly, is why I'm posting into here. This answer is for answering the question "need to move files to different folder based on the creation date [duplicate]"



                        The answers are reasonable but there were some limitations with a purely find command. I wrote this shell script to go through a directory with so many files in it the filesystem was gagging on the metadata trying to perform an ls. Additionally some *nix systems will barf a too many arguments error with running ls.



                        The find command is very powerful and I started with the methods that are listed but I had so many years of data throughout that directory that I had to pass over all the files repeatedly. This produces a lot of needless passed over each file. I tried doing one screen per year and running multiple finds but this resulted in a lot of errors from each find and files would go missing when one of the finds moved it.



                        My shell script moves a file to the destination directory, with a 4 digit year and a 2 digit month. It can easily be expanded to a 2 digit day by uncommenting a couple lines and commenting out their counterparts. I believe it's more efficient because it was perform the moves in one pass of find so multiple find commands and passes over the directory are unneeded.



                        #!/bin/bash
                        #We want to exit if there is no argument submitted
                        if [ -z "$1" ]
                        then
                        echo no input file
                        exit
                        fi

                        #destDir should be set to where ever you want the files to go
                        destDir="/home/user/destination"

                        #Get the month and year of modification time
                        #--format %y returns the modification date in the format:
                        # 2016-04-26 12:40:48.000000000 -0400
                        #We then take the first column, split by a white space with awk
                        date=`stat "$1" --format %y | awk '{ print $1 }'`

                        #This sets the year variable to the first column split on a - with awk
                        year=`echo $date | awk -F- '{print $1 }'`
                        #This sets the month variable to the second column split on a - with awk
                        month=`echo $date | awk -F- '{print $2 }'`
                        #This sets the day variable to the third column split on a - with awk
                        #This is commented out because I didn't want to add day to mine
                        #day=`echo $date | awk -F- '{print $3 }'`

                        #Here we check if the destination directory with year and month exist
                        #If not then we want to create it with -p so the parent is created if
                        # it doesn't already exist
                        if [ ! -d $destDir/$year/$month ]
                        then
                        mkdir -p $destDir/$year/$month || exit
                        fi

                        #This is the same as above but utilizes the day subdirectory
                        #Uncommented this out and comment out the similar code above
                        #if [ ! -d $destDir/$year/$month/$day ]
                        #then
                        # mkdir -p $destDir/$year/$month$day || exit
                        #fi

                        #Echoing out what we're doing
                        #The uncommented is for just year/month and the commented line includes day
                        #Comment the first and uncomment the second if you need day
                        echo Moving $1 to $destDir/$year/$month
                        #echo Moving $1 to $destDir/$year/$month/$day

                        #Move the file to the newly created directory
                        #The uncommented is for just year/month and the commented line includes day
                        #Comment the first and uncomment the second if you need day
                        mv "$1" $destDir/$year/$month
                        #mv "$1" $destDir/$year/$month/$day


                        Once saved and made executable you may call this script with find like the following.



                        find /path/to/directory -type f -exec /home/username/move_files.sh {} ;


                        You don't need to worry about setting the newermt option for find as all find is providing is a single execution per file found and the script makes all the decisions.



                        Keep in mind that if you don't select -type f it will move directories around and that will likely cause issues. You could also use -type d if you're looking to move just directories. Not setting the type will almost certainly produce unwanted behaviour.



                        Remember that this script was tailoured to my needs. You may want to simply use my construct as inspiration for a better suited for your needs script. Thank you!



                        Considerations: The efficiency of the command can be GREATLY improved by allowing an unlimited number of arguments to pass through the script. This is actually relatively easy if you pass over the $@ variable. Extending the functionality of this would allow us to use find's -exec + function or leverage xargs, for example. I may quickly implement that and improve my own answer but this is a start.



                        Since this was a one-shot script session there are probably many improvements that can be made. Good luck!






                        share|improve this answer










                        New contributor




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

























                          0














                          Please note that the question marked as duplicate, and therefore is restricted from answering it directly, is why I'm posting into here. This answer is for answering the question "need to move files to different folder based on the creation date [duplicate]"



                          The answers are reasonable but there were some limitations with a purely find command. I wrote this shell script to go through a directory with so many files in it the filesystem was gagging on the metadata trying to perform an ls. Additionally some *nix systems will barf a too many arguments error with running ls.



                          The find command is very powerful and I started with the methods that are listed but I had so many years of data throughout that directory that I had to pass over all the files repeatedly. This produces a lot of needless passed over each file. I tried doing one screen per year and running multiple finds but this resulted in a lot of errors from each find and files would go missing when one of the finds moved it.



                          My shell script moves a file to the destination directory, with a 4 digit year and a 2 digit month. It can easily be expanded to a 2 digit day by uncommenting a couple lines and commenting out their counterparts. I believe it's more efficient because it was perform the moves in one pass of find so multiple find commands and passes over the directory are unneeded.



                          #!/bin/bash
                          #We want to exit if there is no argument submitted
                          if [ -z "$1" ]
                          then
                          echo no input file
                          exit
                          fi

                          #destDir should be set to where ever you want the files to go
                          destDir="/home/user/destination"

                          #Get the month and year of modification time
                          #--format %y returns the modification date in the format:
                          # 2016-04-26 12:40:48.000000000 -0400
                          #We then take the first column, split by a white space with awk
                          date=`stat "$1" --format %y | awk '{ print $1 }'`

                          #This sets the year variable to the first column split on a - with awk
                          year=`echo $date | awk -F- '{print $1 }'`
                          #This sets the month variable to the second column split on a - with awk
                          month=`echo $date | awk -F- '{print $2 }'`
                          #This sets the day variable to the third column split on a - with awk
                          #This is commented out because I didn't want to add day to mine
                          #day=`echo $date | awk -F- '{print $3 }'`

                          #Here we check if the destination directory with year and month exist
                          #If not then we want to create it with -p so the parent is created if
                          # it doesn't already exist
                          if [ ! -d $destDir/$year/$month ]
                          then
                          mkdir -p $destDir/$year/$month || exit
                          fi

                          #This is the same as above but utilizes the day subdirectory
                          #Uncommented this out and comment out the similar code above
                          #if [ ! -d $destDir/$year/$month/$day ]
                          #then
                          # mkdir -p $destDir/$year/$month$day || exit
                          #fi

                          #Echoing out what we're doing
                          #The uncommented is for just year/month and the commented line includes day
                          #Comment the first and uncomment the second if you need day
                          echo Moving $1 to $destDir/$year/$month
                          #echo Moving $1 to $destDir/$year/$month/$day

                          #Move the file to the newly created directory
                          #The uncommented is for just year/month and the commented line includes day
                          #Comment the first and uncomment the second if you need day
                          mv "$1" $destDir/$year/$month
                          #mv "$1" $destDir/$year/$month/$day


                          Once saved and made executable you may call this script with find like the following.



                          find /path/to/directory -type f -exec /home/username/move_files.sh {} ;


                          You don't need to worry about setting the newermt option for find as all find is providing is a single execution per file found and the script makes all the decisions.



                          Keep in mind that if you don't select -type f it will move directories around and that will likely cause issues. You could also use -type d if you're looking to move just directories. Not setting the type will almost certainly produce unwanted behaviour.



                          Remember that this script was tailoured to my needs. You may want to simply use my construct as inspiration for a better suited for your needs script. Thank you!



                          Considerations: The efficiency of the command can be GREATLY improved by allowing an unlimited number of arguments to pass through the script. This is actually relatively easy if you pass over the $@ variable. Extending the functionality of this would allow us to use find's -exec + function or leverage xargs, for example. I may quickly implement that and improve my own answer but this is a start.



                          Since this was a one-shot script session there are probably many improvements that can be made. Good luck!






                          share|improve this answer










                          New contributor




                          Vex Mage 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







                            Please note that the question marked as duplicate, and therefore is restricted from answering it directly, is why I'm posting into here. This answer is for answering the question "need to move files to different folder based on the creation date [duplicate]"



                            The answers are reasonable but there were some limitations with a purely find command. I wrote this shell script to go through a directory with so many files in it the filesystem was gagging on the metadata trying to perform an ls. Additionally some *nix systems will barf a too many arguments error with running ls.



                            The find command is very powerful and I started with the methods that are listed but I had so many years of data throughout that directory that I had to pass over all the files repeatedly. This produces a lot of needless passed over each file. I tried doing one screen per year and running multiple finds but this resulted in a lot of errors from each find and files would go missing when one of the finds moved it.



                            My shell script moves a file to the destination directory, with a 4 digit year and a 2 digit month. It can easily be expanded to a 2 digit day by uncommenting a couple lines and commenting out their counterparts. I believe it's more efficient because it was perform the moves in one pass of find so multiple find commands and passes over the directory are unneeded.



                            #!/bin/bash
                            #We want to exit if there is no argument submitted
                            if [ -z "$1" ]
                            then
                            echo no input file
                            exit
                            fi

                            #destDir should be set to where ever you want the files to go
                            destDir="/home/user/destination"

                            #Get the month and year of modification time
                            #--format %y returns the modification date in the format:
                            # 2016-04-26 12:40:48.000000000 -0400
                            #We then take the first column, split by a white space with awk
                            date=`stat "$1" --format %y | awk '{ print $1 }'`

                            #This sets the year variable to the first column split on a - with awk
                            year=`echo $date | awk -F- '{print $1 }'`
                            #This sets the month variable to the second column split on a - with awk
                            month=`echo $date | awk -F- '{print $2 }'`
                            #This sets the day variable to the third column split on a - with awk
                            #This is commented out because I didn't want to add day to mine
                            #day=`echo $date | awk -F- '{print $3 }'`

                            #Here we check if the destination directory with year and month exist
                            #If not then we want to create it with -p so the parent is created if
                            # it doesn't already exist
                            if [ ! -d $destDir/$year/$month ]
                            then
                            mkdir -p $destDir/$year/$month || exit
                            fi

                            #This is the same as above but utilizes the day subdirectory
                            #Uncommented this out and comment out the similar code above
                            #if [ ! -d $destDir/$year/$month/$day ]
                            #then
                            # mkdir -p $destDir/$year/$month$day || exit
                            #fi

                            #Echoing out what we're doing
                            #The uncommented is for just year/month and the commented line includes day
                            #Comment the first and uncomment the second if you need day
                            echo Moving $1 to $destDir/$year/$month
                            #echo Moving $1 to $destDir/$year/$month/$day

                            #Move the file to the newly created directory
                            #The uncommented is for just year/month and the commented line includes day
                            #Comment the first and uncomment the second if you need day
                            mv "$1" $destDir/$year/$month
                            #mv "$1" $destDir/$year/$month/$day


                            Once saved and made executable you may call this script with find like the following.



                            find /path/to/directory -type f -exec /home/username/move_files.sh {} ;


                            You don't need to worry about setting the newermt option for find as all find is providing is a single execution per file found and the script makes all the decisions.



                            Keep in mind that if you don't select -type f it will move directories around and that will likely cause issues. You could also use -type d if you're looking to move just directories. Not setting the type will almost certainly produce unwanted behaviour.



                            Remember that this script was tailoured to my needs. You may want to simply use my construct as inspiration for a better suited for your needs script. Thank you!



                            Considerations: The efficiency of the command can be GREATLY improved by allowing an unlimited number of arguments to pass through the script. This is actually relatively easy if you pass over the $@ variable. Extending the functionality of this would allow us to use find's -exec + function or leverage xargs, for example. I may quickly implement that and improve my own answer but this is a start.



                            Since this was a one-shot script session there are probably many improvements that can be made. Good luck!






                            share|improve this answer










                            New contributor




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










                            Please note that the question marked as duplicate, and therefore is restricted from answering it directly, is why I'm posting into here. This answer is for answering the question "need to move files to different folder based on the creation date [duplicate]"



                            The answers are reasonable but there were some limitations with a purely find command. I wrote this shell script to go through a directory with so many files in it the filesystem was gagging on the metadata trying to perform an ls. Additionally some *nix systems will barf a too many arguments error with running ls.



                            The find command is very powerful and I started with the methods that are listed but I had so many years of data throughout that directory that I had to pass over all the files repeatedly. This produces a lot of needless passed over each file. I tried doing one screen per year and running multiple finds but this resulted in a lot of errors from each find and files would go missing when one of the finds moved it.



                            My shell script moves a file to the destination directory, with a 4 digit year and a 2 digit month. It can easily be expanded to a 2 digit day by uncommenting a couple lines and commenting out their counterparts. I believe it's more efficient because it was perform the moves in one pass of find so multiple find commands and passes over the directory are unneeded.



                            #!/bin/bash
                            #We want to exit if there is no argument submitted
                            if [ -z "$1" ]
                            then
                            echo no input file
                            exit
                            fi

                            #destDir should be set to where ever you want the files to go
                            destDir="/home/user/destination"

                            #Get the month and year of modification time
                            #--format %y returns the modification date in the format:
                            # 2016-04-26 12:40:48.000000000 -0400
                            #We then take the first column, split by a white space with awk
                            date=`stat "$1" --format %y | awk '{ print $1 }'`

                            #This sets the year variable to the first column split on a - with awk
                            year=`echo $date | awk -F- '{print $1 }'`
                            #This sets the month variable to the second column split on a - with awk
                            month=`echo $date | awk -F- '{print $2 }'`
                            #This sets the day variable to the third column split on a - with awk
                            #This is commented out because I didn't want to add day to mine
                            #day=`echo $date | awk -F- '{print $3 }'`

                            #Here we check if the destination directory with year and month exist
                            #If not then we want to create it with -p so the parent is created if
                            # it doesn't already exist
                            if [ ! -d $destDir/$year/$month ]
                            then
                            mkdir -p $destDir/$year/$month || exit
                            fi

                            #This is the same as above but utilizes the day subdirectory
                            #Uncommented this out and comment out the similar code above
                            #if [ ! -d $destDir/$year/$month/$day ]
                            #then
                            # mkdir -p $destDir/$year/$month$day || exit
                            #fi

                            #Echoing out what we're doing
                            #The uncommented is for just year/month and the commented line includes day
                            #Comment the first and uncomment the second if you need day
                            echo Moving $1 to $destDir/$year/$month
                            #echo Moving $1 to $destDir/$year/$month/$day

                            #Move the file to the newly created directory
                            #The uncommented is for just year/month and the commented line includes day
                            #Comment the first and uncomment the second if you need day
                            mv "$1" $destDir/$year/$month
                            #mv "$1" $destDir/$year/$month/$day


                            Once saved and made executable you may call this script with find like the following.



                            find /path/to/directory -type f -exec /home/username/move_files.sh {} ;


                            You don't need to worry about setting the newermt option for find as all find is providing is a single execution per file found and the script makes all the decisions.



                            Keep in mind that if you don't select -type f it will move directories around and that will likely cause issues. You could also use -type d if you're looking to move just directories. Not setting the type will almost certainly produce unwanted behaviour.



                            Remember that this script was tailoured to my needs. You may want to simply use my construct as inspiration for a better suited for your needs script. Thank you!



                            Considerations: The efficiency of the command can be GREATLY improved by allowing an unlimited number of arguments to pass through the script. This is actually relatively easy if you pass over the $@ variable. Extending the functionality of this would allow us to use find's -exec + function or leverage xargs, for example. I may quickly implement that and improve my own answer but this is a start.



                            Since this was a one-shot script session there are probably many improvements that can be made. Good luck!







                            share|improve this answer










                            New contributor




                            Vex Mage 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








                            edited 2 hours ago





















                            New contributor




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









                            answered 2 hours ago









                            Vex MageVex Mage

                            11




                            11




                            New contributor




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





                            New contributor





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






                            Vex Mage 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%2f29245%2fhow-to-list-files-that-were-changed-in-a-certain-range-of-time%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

                                Histoire des bourses de valeurs

                                Why is there Russian traffic in my log files?

                                Rename multiple files to decrement number in file name?