How to delete files older than X hours











up vote
162
down vote

favorite
44












I'm writing a bash script that needs to delete old files.



It's currently implemented using :



find $LOCATION -name $REQUIRED_FILES -type f -mtime +1 -delete


This will delete of the files older than 1 day.



However, what if I need a finer resolution that 1 day, say like 6 hours old? Is there a nice clean way to do it, like there is using find and -mtime?










share|improve this question


























    up vote
    162
    down vote

    favorite
    44












    I'm writing a bash script that needs to delete old files.



    It's currently implemented using :



    find $LOCATION -name $REQUIRED_FILES -type f -mtime +1 -delete


    This will delete of the files older than 1 day.



    However, what if I need a finer resolution that 1 day, say like 6 hours old? Is there a nice clean way to do it, like there is using find and -mtime?










    share|improve this question
























      up vote
      162
      down vote

      favorite
      44









      up vote
      162
      down vote

      favorite
      44






      44





      I'm writing a bash script that needs to delete old files.



      It's currently implemented using :



      find $LOCATION -name $REQUIRED_FILES -type f -mtime +1 -delete


      This will delete of the files older than 1 day.



      However, what if I need a finer resolution that 1 day, say like 6 hours old? Is there a nice clean way to do it, like there is using find and -mtime?










      share|improve this question













      I'm writing a bash script that needs to delete old files.



      It's currently implemented using :



      find $LOCATION -name $REQUIRED_FILES -type f -mtime +1 -delete


      This will delete of the files older than 1 day.



      However, what if I need a finer resolution that 1 day, say like 6 hours old? Is there a nice clean way to do it, like there is using find and -mtime?







      bash






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Oct 30 '08 at 8:31









      Tom Feiner

      8,111154251




      8,111154251
























          8 Answers
          8






          active

          oldest

          votes

















          up vote
          250
          down vote



          accepted










          Does your find have the -mmin option? That can let you test the number of mins since last modification:



          find $LOCATION -name $REQUIRED_FILES -type f -mmin +360 -delete


          Or maybe look at using tmpwatch to do the same job. phjr also recommended tmpreaper in the comments.






          share|improve this answer



















          • 5




            Thanks for the answers everyone, -mmin is exactly what I needed :) somehow I missed it in the man page.
            – Tom Feiner
            Oct 30 '08 at 8:43






          • 2




            Mine doesn't have -mmin :(
            – xtofl
            Oct 30 '08 at 8:45






          • 2




            tmpwatch is for you then!
            – Paul Dixon
            Oct 30 '08 at 8:48










          • I find tmpreaper better than tmpwatch - could you also include it in your answer? Thanks.
            – Paweł Hajdan
            Oct 30 '08 at 12:37










          • Using --mmin +X returns all files with my find. My fault for not checking this first, but this command just deleted most of my home directory. For me, --mmin -X is the correct argument.
            – brandones
            Oct 16 '13 at 0:08


















          up vote
          7
          down vote













          You could to this trick: create a file 1 hour ago, and use the -newer file argument.



          (Or use touch -t to create such a file).






          share|improve this answer

















          • 2




            Yeah, I found this trick in google, however -mmin is much more elegant.
            – Tom Feiner
            Oct 30 '08 at 8:56






          • 1




            there is no -older switch (at least in my find command), and that's what would be needed. -newer doesn't help.
            – iconoclast
            Feb 17 '11 at 6:53








          • 5




            @Brandon: luckily, there is the ! operator...
            – xtofl
            Feb 17 '11 at 8:39










          • can you give a touch command that would generate a file 1 hour old that will work on machines that can't use -mmin? (If you're on Linux, -mmin is available, if not then date and other commands are also feeble in comparison.)
            – iconoclast
            May 10 '11 at 17:20








          • 1




            @iconoclast touch -t $(date -d '-1 hour' +%Y%m%d%H%M.00) test Creates file test that's always 1 hour old.
            – rovr138
            Jan 20 at 15:29


















          up vote
          2
          down vote













          Here is the approach that worked for me (and I don't see it being used above)



          $ find /path/to/the/folder -name *.* -mmin +59 -delete > /dev/null


          deleting all the files older than 59 minutes while leaving the folders intact.






          share|improve this answer






























            up vote
            1
            down vote













            For SunOS 5.10



             Example 6 Selecting a File Using 24-hour Mode


            The descriptions of -atime, -ctime, and -mtime use the ter-
            minology n ``24-hour periods''. For example, a file accessed
            at 23:59 is selected by:


            example% find . -atime -1 -print




            at 00:01 the next day (less than 24 hours later, not more
            than one day ago). The midnight boundary between days has no
            effect on the 24-hour calculation.





            share|improve this answer






























              up vote
              0
              down vote













              -mmin is for minutes.



              Try looking at the man page.



              man find


              for more types.






              share|improve this answer




























                up vote
                0
                down vote













                If you do not have "-mmin" in your version of "find", then "-mtime -0.041667" gets pretty close to "within the last hour", so in your case, use:



                -mtime +(X * 0.041667)


                so, if X means 6 hours, then:



                find . -mtime +0.25 -ls


                works because 24 hours * 0.25 = 6 hours






                share|improve this answer




























                  up vote
                  0
                  down vote













                  Here is what one can do for going on the way @iconoclast was wondering about in their comment on another answer.



                  use crontab for user or an /etc/crontab to create file /tmp/hour:



                  # m h dom mon dow user  command
                  0 * * * * root /usr/bin/touch /tmp/hour > /dev/null 2>&1


                  and then use this to run your command:



                  find /tmp/ -daystart -maxdepth 1 -not -newer /tmp/hour -type f -name "for_one_hour_files*" -exec do_something {} ;





                  share|improve this answer























                  • No problem. @ericaya actually did most of it, I just touched things up.
                    – Paul Roub
                    Jun 13 '17 at 13:34










                  • */1 for hourly is redundant in your crontab. It's the same as putting * in the hour field.
                    – colminator
                    Jun 20 '17 at 18:10










                  • @columnator -you are right, I've corrected my entry.
                    – satyr0909
                    Jul 11 '17 at 14:17


















                  up vote
                  0
                  down vote













                  find $PATH -name $log_prefix"*"$log_ext -mmin +$num_mins -exec rm -f {} ;






                  share|improve this answer























                    Your Answer






                    StackExchange.ifUsing("editor", function () {
                    StackExchange.using("externalEditor", function () {
                    StackExchange.using("snippets", function () {
                    StackExchange.snippets.init();
                    });
                    });
                    }, "code-snippets");

                    StackExchange.ready(function() {
                    var channelOptions = {
                    tags: "".split(" "),
                    id: "1"
                    };
                    initTagRenderer("".split(" "), "".split(" "), channelOptions);

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

                    function createEditor() {
                    StackExchange.prepareEditor({
                    heartbeatType: 'answer',
                    convertImagesToLinks: true,
                    noModals: true,
                    showLowRepImageUploadWarning: true,
                    reputationToPostImages: 10,
                    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%2fstackoverflow.com%2fquestions%2f249578%2fhow-to-delete-files-older-than-x-hours%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown

























                    8 Answers
                    8






                    active

                    oldest

                    votes








                    8 Answers
                    8






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes








                    up vote
                    250
                    down vote



                    accepted










                    Does your find have the -mmin option? That can let you test the number of mins since last modification:



                    find $LOCATION -name $REQUIRED_FILES -type f -mmin +360 -delete


                    Or maybe look at using tmpwatch to do the same job. phjr also recommended tmpreaper in the comments.






                    share|improve this answer



















                    • 5




                      Thanks for the answers everyone, -mmin is exactly what I needed :) somehow I missed it in the man page.
                      – Tom Feiner
                      Oct 30 '08 at 8:43






                    • 2




                      Mine doesn't have -mmin :(
                      – xtofl
                      Oct 30 '08 at 8:45






                    • 2




                      tmpwatch is for you then!
                      – Paul Dixon
                      Oct 30 '08 at 8:48










                    • I find tmpreaper better than tmpwatch - could you also include it in your answer? Thanks.
                      – Paweł Hajdan
                      Oct 30 '08 at 12:37










                    • Using --mmin +X returns all files with my find. My fault for not checking this first, but this command just deleted most of my home directory. For me, --mmin -X is the correct argument.
                      – brandones
                      Oct 16 '13 at 0:08















                    up vote
                    250
                    down vote



                    accepted










                    Does your find have the -mmin option? That can let you test the number of mins since last modification:



                    find $LOCATION -name $REQUIRED_FILES -type f -mmin +360 -delete


                    Or maybe look at using tmpwatch to do the same job. phjr also recommended tmpreaper in the comments.






                    share|improve this answer



















                    • 5




                      Thanks for the answers everyone, -mmin is exactly what I needed :) somehow I missed it in the man page.
                      – Tom Feiner
                      Oct 30 '08 at 8:43






                    • 2




                      Mine doesn't have -mmin :(
                      – xtofl
                      Oct 30 '08 at 8:45






                    • 2




                      tmpwatch is for you then!
                      – Paul Dixon
                      Oct 30 '08 at 8:48










                    • I find tmpreaper better than tmpwatch - could you also include it in your answer? Thanks.
                      – Paweł Hajdan
                      Oct 30 '08 at 12:37










                    • Using --mmin +X returns all files with my find. My fault for not checking this first, but this command just deleted most of my home directory. For me, --mmin -X is the correct argument.
                      – brandones
                      Oct 16 '13 at 0:08













                    up vote
                    250
                    down vote



                    accepted







                    up vote
                    250
                    down vote



                    accepted






                    Does your find have the -mmin option? That can let you test the number of mins since last modification:



                    find $LOCATION -name $REQUIRED_FILES -type f -mmin +360 -delete


                    Or maybe look at using tmpwatch to do the same job. phjr also recommended tmpreaper in the comments.






                    share|improve this answer














                    Does your find have the -mmin option? That can let you test the number of mins since last modification:



                    find $LOCATION -name $REQUIRED_FILES -type f -mmin +360 -delete


                    Or maybe look at using tmpwatch to do the same job. phjr also recommended tmpreaper in the comments.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 11 at 8:09









                    Bitcoin Murderous Maniac

                    4831616




                    4831616










                    answered Oct 30 '08 at 8:39









                    Paul Dixon

                    238k40281316




                    238k40281316








                    • 5




                      Thanks for the answers everyone, -mmin is exactly what I needed :) somehow I missed it in the man page.
                      – Tom Feiner
                      Oct 30 '08 at 8:43






                    • 2




                      Mine doesn't have -mmin :(
                      – xtofl
                      Oct 30 '08 at 8:45






                    • 2




                      tmpwatch is for you then!
                      – Paul Dixon
                      Oct 30 '08 at 8:48










                    • I find tmpreaper better than tmpwatch - could you also include it in your answer? Thanks.
                      – Paweł Hajdan
                      Oct 30 '08 at 12:37










                    • Using --mmin +X returns all files with my find. My fault for not checking this first, but this command just deleted most of my home directory. For me, --mmin -X is the correct argument.
                      – brandones
                      Oct 16 '13 at 0:08














                    • 5




                      Thanks for the answers everyone, -mmin is exactly what I needed :) somehow I missed it in the man page.
                      – Tom Feiner
                      Oct 30 '08 at 8:43






                    • 2




                      Mine doesn't have -mmin :(
                      – xtofl
                      Oct 30 '08 at 8:45






                    • 2




                      tmpwatch is for you then!
                      – Paul Dixon
                      Oct 30 '08 at 8:48










                    • I find tmpreaper better than tmpwatch - could you also include it in your answer? Thanks.
                      – Paweł Hajdan
                      Oct 30 '08 at 12:37










                    • Using --mmin +X returns all files with my find. My fault for not checking this first, but this command just deleted most of my home directory. For me, --mmin -X is the correct argument.
                      – brandones
                      Oct 16 '13 at 0:08








                    5




                    5




                    Thanks for the answers everyone, -mmin is exactly what I needed :) somehow I missed it in the man page.
                    – Tom Feiner
                    Oct 30 '08 at 8:43




                    Thanks for the answers everyone, -mmin is exactly what I needed :) somehow I missed it in the man page.
                    – Tom Feiner
                    Oct 30 '08 at 8:43




                    2




                    2




                    Mine doesn't have -mmin :(
                    – xtofl
                    Oct 30 '08 at 8:45




                    Mine doesn't have -mmin :(
                    – xtofl
                    Oct 30 '08 at 8:45




                    2




                    2




                    tmpwatch is for you then!
                    – Paul Dixon
                    Oct 30 '08 at 8:48




                    tmpwatch is for you then!
                    – Paul Dixon
                    Oct 30 '08 at 8:48












                    I find tmpreaper better than tmpwatch - could you also include it in your answer? Thanks.
                    – Paweł Hajdan
                    Oct 30 '08 at 12:37




                    I find tmpreaper better than tmpwatch - could you also include it in your answer? Thanks.
                    – Paweł Hajdan
                    Oct 30 '08 at 12:37












                    Using --mmin +X returns all files with my find. My fault for not checking this first, but this command just deleted most of my home directory. For me, --mmin -X is the correct argument.
                    – brandones
                    Oct 16 '13 at 0:08




                    Using --mmin +X returns all files with my find. My fault for not checking this first, but this command just deleted most of my home directory. For me, --mmin -X is the correct argument.
                    – brandones
                    Oct 16 '13 at 0:08












                    up vote
                    7
                    down vote













                    You could to this trick: create a file 1 hour ago, and use the -newer file argument.



                    (Or use touch -t to create such a file).






                    share|improve this answer

















                    • 2




                      Yeah, I found this trick in google, however -mmin is much more elegant.
                      – Tom Feiner
                      Oct 30 '08 at 8:56






                    • 1




                      there is no -older switch (at least in my find command), and that's what would be needed. -newer doesn't help.
                      – iconoclast
                      Feb 17 '11 at 6:53








                    • 5




                      @Brandon: luckily, there is the ! operator...
                      – xtofl
                      Feb 17 '11 at 8:39










                    • can you give a touch command that would generate a file 1 hour old that will work on machines that can't use -mmin? (If you're on Linux, -mmin is available, if not then date and other commands are also feeble in comparison.)
                      – iconoclast
                      May 10 '11 at 17:20








                    • 1




                      @iconoclast touch -t $(date -d '-1 hour' +%Y%m%d%H%M.00) test Creates file test that's always 1 hour old.
                      – rovr138
                      Jan 20 at 15:29















                    up vote
                    7
                    down vote













                    You could to this trick: create a file 1 hour ago, and use the -newer file argument.



                    (Or use touch -t to create such a file).






                    share|improve this answer

















                    • 2




                      Yeah, I found this trick in google, however -mmin is much more elegant.
                      – Tom Feiner
                      Oct 30 '08 at 8:56






                    • 1




                      there is no -older switch (at least in my find command), and that's what would be needed. -newer doesn't help.
                      – iconoclast
                      Feb 17 '11 at 6:53








                    • 5




                      @Brandon: luckily, there is the ! operator...
                      – xtofl
                      Feb 17 '11 at 8:39










                    • can you give a touch command that would generate a file 1 hour old that will work on machines that can't use -mmin? (If you're on Linux, -mmin is available, if not then date and other commands are also feeble in comparison.)
                      – iconoclast
                      May 10 '11 at 17:20








                    • 1




                      @iconoclast touch -t $(date -d '-1 hour' +%Y%m%d%H%M.00) test Creates file test that's always 1 hour old.
                      – rovr138
                      Jan 20 at 15:29













                    up vote
                    7
                    down vote










                    up vote
                    7
                    down vote









                    You could to this trick: create a file 1 hour ago, and use the -newer file argument.



                    (Or use touch -t to create such a file).






                    share|improve this answer












                    You could to this trick: create a file 1 hour ago, and use the -newer file argument.



                    (Or use touch -t to create such a file).







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Oct 30 '08 at 8:51









                    xtofl

                    31.5k678160




                    31.5k678160








                    • 2




                      Yeah, I found this trick in google, however -mmin is much more elegant.
                      – Tom Feiner
                      Oct 30 '08 at 8:56






                    • 1




                      there is no -older switch (at least in my find command), and that's what would be needed. -newer doesn't help.
                      – iconoclast
                      Feb 17 '11 at 6:53








                    • 5




                      @Brandon: luckily, there is the ! operator...
                      – xtofl
                      Feb 17 '11 at 8:39










                    • can you give a touch command that would generate a file 1 hour old that will work on machines that can't use -mmin? (If you're on Linux, -mmin is available, if not then date and other commands are also feeble in comparison.)
                      – iconoclast
                      May 10 '11 at 17:20








                    • 1




                      @iconoclast touch -t $(date -d '-1 hour' +%Y%m%d%H%M.00) test Creates file test that's always 1 hour old.
                      – rovr138
                      Jan 20 at 15:29














                    • 2




                      Yeah, I found this trick in google, however -mmin is much more elegant.
                      – Tom Feiner
                      Oct 30 '08 at 8:56






                    • 1




                      there is no -older switch (at least in my find command), and that's what would be needed. -newer doesn't help.
                      – iconoclast
                      Feb 17 '11 at 6:53








                    • 5




                      @Brandon: luckily, there is the ! operator...
                      – xtofl
                      Feb 17 '11 at 8:39










                    • can you give a touch command that would generate a file 1 hour old that will work on machines that can't use -mmin? (If you're on Linux, -mmin is available, if not then date and other commands are also feeble in comparison.)
                      – iconoclast
                      May 10 '11 at 17:20








                    • 1




                      @iconoclast touch -t $(date -d '-1 hour' +%Y%m%d%H%M.00) test Creates file test that's always 1 hour old.
                      – rovr138
                      Jan 20 at 15:29








                    2




                    2




                    Yeah, I found this trick in google, however -mmin is much more elegant.
                    – Tom Feiner
                    Oct 30 '08 at 8:56




                    Yeah, I found this trick in google, however -mmin is much more elegant.
                    – Tom Feiner
                    Oct 30 '08 at 8:56




                    1




                    1




                    there is no -older switch (at least in my find command), and that's what would be needed. -newer doesn't help.
                    – iconoclast
                    Feb 17 '11 at 6:53






                    there is no -older switch (at least in my find command), and that's what would be needed. -newer doesn't help.
                    – iconoclast
                    Feb 17 '11 at 6:53






                    5




                    5




                    @Brandon: luckily, there is the ! operator...
                    – xtofl
                    Feb 17 '11 at 8:39




                    @Brandon: luckily, there is the ! operator...
                    – xtofl
                    Feb 17 '11 at 8:39












                    can you give a touch command that would generate a file 1 hour old that will work on machines that can't use -mmin? (If you're on Linux, -mmin is available, if not then date and other commands are also feeble in comparison.)
                    – iconoclast
                    May 10 '11 at 17:20






                    can you give a touch command that would generate a file 1 hour old that will work on machines that can't use -mmin? (If you're on Linux, -mmin is available, if not then date and other commands are also feeble in comparison.)
                    – iconoclast
                    May 10 '11 at 17:20






                    1




                    1




                    @iconoclast touch -t $(date -d '-1 hour' +%Y%m%d%H%M.00) test Creates file test that's always 1 hour old.
                    – rovr138
                    Jan 20 at 15:29




                    @iconoclast touch -t $(date -d '-1 hour' +%Y%m%d%H%M.00) test Creates file test that's always 1 hour old.
                    – rovr138
                    Jan 20 at 15:29










                    up vote
                    2
                    down vote













                    Here is the approach that worked for me (and I don't see it being used above)



                    $ find /path/to/the/folder -name *.* -mmin +59 -delete > /dev/null


                    deleting all the files older than 59 minutes while leaving the folders intact.






                    share|improve this answer



























                      up vote
                      2
                      down vote













                      Here is the approach that worked for me (and I don't see it being used above)



                      $ find /path/to/the/folder -name *.* -mmin +59 -delete > /dev/null


                      deleting all the files older than 59 minutes while leaving the folders intact.






                      share|improve this answer

























                        up vote
                        2
                        down vote










                        up vote
                        2
                        down vote









                        Here is the approach that worked for me (and I don't see it being used above)



                        $ find /path/to/the/folder -name *.* -mmin +59 -delete > /dev/null


                        deleting all the files older than 59 minutes while leaving the folders intact.






                        share|improve this answer














                        Here is the approach that worked for me (and I don't see it being used above)



                        $ find /path/to/the/folder -name *.* -mmin +59 -delete > /dev/null


                        deleting all the files older than 59 minutes while leaving the folders intact.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Feb 20 at 14:36









                        iBug

                        16.5k53359




                        16.5k53359










                        answered Feb 20 at 14:36









                        Axel Ronsin

                        212




                        212






















                            up vote
                            1
                            down vote













                            For SunOS 5.10



                             Example 6 Selecting a File Using 24-hour Mode


                            The descriptions of -atime, -ctime, and -mtime use the ter-
                            minology n ``24-hour periods''. For example, a file accessed
                            at 23:59 is selected by:


                            example% find . -atime -1 -print




                            at 00:01 the next day (less than 24 hours later, not more
                            than one day ago). The midnight boundary between days has no
                            effect on the 24-hour calculation.





                            share|improve this answer



























                              up vote
                              1
                              down vote













                              For SunOS 5.10



                               Example 6 Selecting a File Using 24-hour Mode


                              The descriptions of -atime, -ctime, and -mtime use the ter-
                              minology n ``24-hour periods''. For example, a file accessed
                              at 23:59 is selected by:


                              example% find . -atime -1 -print




                              at 00:01 the next day (less than 24 hours later, not more
                              than one day ago). The midnight boundary between days has no
                              effect on the 24-hour calculation.





                              share|improve this answer

























                                up vote
                                1
                                down vote










                                up vote
                                1
                                down vote









                                For SunOS 5.10



                                 Example 6 Selecting a File Using 24-hour Mode


                                The descriptions of -atime, -ctime, and -mtime use the ter-
                                minology n ``24-hour periods''. For example, a file accessed
                                at 23:59 is selected by:


                                example% find . -atime -1 -print




                                at 00:01 the next day (less than 24 hours later, not more
                                than one day ago). The midnight boundary between days has no
                                effect on the 24-hour calculation.





                                share|improve this answer














                                For SunOS 5.10



                                 Example 6 Selecting a File Using 24-hour Mode


                                The descriptions of -atime, -ctime, and -mtime use the ter-
                                minology n ``24-hour periods''. For example, a file accessed
                                at 23:59 is selected by:


                                example% find . -atime -1 -print




                                at 00:01 the next day (less than 24 hours later, not more
                                than one day ago). The midnight boundary between days has no
                                effect on the 24-hour calculation.






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited May 4 '12 at 14:41









                                Darren

                                52.9k1599113




                                52.9k1599113










                                answered Jun 2 '10 at 11:37









                                Rajeev Rumale

                                111




                                111






















                                    up vote
                                    0
                                    down vote













                                    -mmin is for minutes.



                                    Try looking at the man page.



                                    man find


                                    for more types.






                                    share|improve this answer

























                                      up vote
                                      0
                                      down vote













                                      -mmin is for minutes.



                                      Try looking at the man page.



                                      man find


                                      for more types.






                                      share|improve this answer























                                        up vote
                                        0
                                        down vote










                                        up vote
                                        0
                                        down vote









                                        -mmin is for minutes.



                                        Try looking at the man page.



                                        man find


                                        for more types.






                                        share|improve this answer












                                        -mmin is for minutes.



                                        Try looking at the man page.



                                        man find


                                        for more types.







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Oct 30 '08 at 8:37









                                        GavinCattell

                                        3,3531520




                                        3,3531520






















                                            up vote
                                            0
                                            down vote













                                            If you do not have "-mmin" in your version of "find", then "-mtime -0.041667" gets pretty close to "within the last hour", so in your case, use:



                                            -mtime +(X * 0.041667)


                                            so, if X means 6 hours, then:



                                            find . -mtime +0.25 -ls


                                            works because 24 hours * 0.25 = 6 hours






                                            share|improve this answer

























                                              up vote
                                              0
                                              down vote













                                              If you do not have "-mmin" in your version of "find", then "-mtime -0.041667" gets pretty close to "within the last hour", so in your case, use:



                                              -mtime +(X * 0.041667)


                                              so, if X means 6 hours, then:



                                              find . -mtime +0.25 -ls


                                              works because 24 hours * 0.25 = 6 hours






                                              share|improve this answer























                                                up vote
                                                0
                                                down vote










                                                up vote
                                                0
                                                down vote









                                                If you do not have "-mmin" in your version of "find", then "-mtime -0.041667" gets pretty close to "within the last hour", so in your case, use:



                                                -mtime +(X * 0.041667)


                                                so, if X means 6 hours, then:



                                                find . -mtime +0.25 -ls


                                                works because 24 hours * 0.25 = 6 hours






                                                share|improve this answer












                                                If you do not have "-mmin" in your version of "find", then "-mtime -0.041667" gets pretty close to "within the last hour", so in your case, use:



                                                -mtime +(X * 0.041667)


                                                so, if X means 6 hours, then:



                                                find . -mtime +0.25 -ls


                                                works because 24 hours * 0.25 = 6 hours







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Jun 30 '17 at 2:25









                                                Malcolm Boekhoff

                                                65696




                                                65696






















                                                    up vote
                                                    0
                                                    down vote













                                                    Here is what one can do for going on the way @iconoclast was wondering about in their comment on another answer.



                                                    use crontab for user or an /etc/crontab to create file /tmp/hour:



                                                    # m h dom mon dow user  command
                                                    0 * * * * root /usr/bin/touch /tmp/hour > /dev/null 2>&1


                                                    and then use this to run your command:



                                                    find /tmp/ -daystart -maxdepth 1 -not -newer /tmp/hour -type f -name "for_one_hour_files*" -exec do_something {} ;





                                                    share|improve this answer























                                                    • No problem. @ericaya actually did most of it, I just touched things up.
                                                      – Paul Roub
                                                      Jun 13 '17 at 13:34










                                                    • */1 for hourly is redundant in your crontab. It's the same as putting * in the hour field.
                                                      – colminator
                                                      Jun 20 '17 at 18:10










                                                    • @columnator -you are right, I've corrected my entry.
                                                      – satyr0909
                                                      Jul 11 '17 at 14:17















                                                    up vote
                                                    0
                                                    down vote













                                                    Here is what one can do for going on the way @iconoclast was wondering about in their comment on another answer.



                                                    use crontab for user or an /etc/crontab to create file /tmp/hour:



                                                    # m h dom mon dow user  command
                                                    0 * * * * root /usr/bin/touch /tmp/hour > /dev/null 2>&1


                                                    and then use this to run your command:



                                                    find /tmp/ -daystart -maxdepth 1 -not -newer /tmp/hour -type f -name "for_one_hour_files*" -exec do_something {} ;





                                                    share|improve this answer























                                                    • No problem. @ericaya actually did most of it, I just touched things up.
                                                      – Paul Roub
                                                      Jun 13 '17 at 13:34










                                                    • */1 for hourly is redundant in your crontab. It's the same as putting * in the hour field.
                                                      – colminator
                                                      Jun 20 '17 at 18:10










                                                    • @columnator -you are right, I've corrected my entry.
                                                      – satyr0909
                                                      Jul 11 '17 at 14:17













                                                    up vote
                                                    0
                                                    down vote










                                                    up vote
                                                    0
                                                    down vote









                                                    Here is what one can do for going on the way @iconoclast was wondering about in their comment on another answer.



                                                    use crontab for user or an /etc/crontab to create file /tmp/hour:



                                                    # m h dom mon dow user  command
                                                    0 * * * * root /usr/bin/touch /tmp/hour > /dev/null 2>&1


                                                    and then use this to run your command:



                                                    find /tmp/ -daystart -maxdepth 1 -not -newer /tmp/hour -type f -name "for_one_hour_files*" -exec do_something {} ;





                                                    share|improve this answer














                                                    Here is what one can do for going on the way @iconoclast was wondering about in their comment on another answer.



                                                    use crontab for user or an /etc/crontab to create file /tmp/hour:



                                                    # m h dom mon dow user  command
                                                    0 * * * * root /usr/bin/touch /tmp/hour > /dev/null 2>&1


                                                    and then use this to run your command:



                                                    find /tmp/ -daystart -maxdepth 1 -not -newer /tmp/hour -type f -name "for_one_hour_files*" -exec do_something {} ;






                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Jul 11 '17 at 14:15

























                                                    answered Jun 13 '17 at 13:10









                                                    satyr0909

                                                    112




                                                    112












                                                    • No problem. @ericaya actually did most of it, I just touched things up.
                                                      – Paul Roub
                                                      Jun 13 '17 at 13:34










                                                    • */1 for hourly is redundant in your crontab. It's the same as putting * in the hour field.
                                                      – colminator
                                                      Jun 20 '17 at 18:10










                                                    • @columnator -you are right, I've corrected my entry.
                                                      – satyr0909
                                                      Jul 11 '17 at 14:17


















                                                    • No problem. @ericaya actually did most of it, I just touched things up.
                                                      – Paul Roub
                                                      Jun 13 '17 at 13:34










                                                    • */1 for hourly is redundant in your crontab. It's the same as putting * in the hour field.
                                                      – colminator
                                                      Jun 20 '17 at 18:10










                                                    • @columnator -you are right, I've corrected my entry.
                                                      – satyr0909
                                                      Jul 11 '17 at 14:17
















                                                    No problem. @ericaya actually did most of it, I just touched things up.
                                                    – Paul Roub
                                                    Jun 13 '17 at 13:34




                                                    No problem. @ericaya actually did most of it, I just touched things up.
                                                    – Paul Roub
                                                    Jun 13 '17 at 13:34












                                                    */1 for hourly is redundant in your crontab. It's the same as putting * in the hour field.
                                                    – colminator
                                                    Jun 20 '17 at 18:10




                                                    */1 for hourly is redundant in your crontab. It's the same as putting * in the hour field.
                                                    – colminator
                                                    Jun 20 '17 at 18:10












                                                    @columnator -you are right, I've corrected my entry.
                                                    – satyr0909
                                                    Jul 11 '17 at 14:17




                                                    @columnator -you are right, I've corrected my entry.
                                                    – satyr0909
                                                    Jul 11 '17 at 14:17










                                                    up vote
                                                    0
                                                    down vote













                                                    find $PATH -name $log_prefix"*"$log_ext -mmin +$num_mins -exec rm -f {} ;






                                                    share|improve this answer



























                                                      up vote
                                                      0
                                                      down vote













                                                      find $PATH -name $log_prefix"*"$log_ext -mmin +$num_mins -exec rm -f {} ;






                                                      share|improve this answer

























                                                        up vote
                                                        0
                                                        down vote










                                                        up vote
                                                        0
                                                        down vote









                                                        find $PATH -name $log_prefix"*"$log_ext -mmin +$num_mins -exec rm -f {} ;






                                                        share|improve this answer














                                                        find $PATH -name $log_prefix"*"$log_ext -mmin +$num_mins -exec rm -f {} ;







                                                        share|improve this answer














                                                        share|improve this answer



                                                        share|improve this answer








                                                        edited Jan 13 at 18:57









                                                        shukshin.ivan

                                                        7,82522856




                                                        7,82522856










                                                        answered Oct 31 '16 at 22:32









                                                        Eragonz91

                                                        127112




                                                        127112






























                                                            draft saved

                                                            draft discarded




















































                                                            Thanks for contributing an answer to Stack Overflow!


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

                                                            But avoid



                                                            • Asking for help, clarification, or responding to other answers.

                                                            • Making statements based on opinion; back them up with references or personal experience.


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





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


                                                            Please pay close attention to the following guidance:


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

                                                            But avoid



                                                            • Asking for help, clarification, or responding to other answers.

                                                            • Making statements based on opinion; back them up with references or personal experience.


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




                                                            draft saved


                                                            draft discarded














                                                            StackExchange.ready(
                                                            function () {
                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f249578%2fhow-to-delete-files-older-than-x-hours%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

                                                            Bressuire

                                                            Vorschmack

                                                            Quarantine