deleting files older than a specific day and excluding the direct files under folder

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











up vote
0
down vote

favorite












I would like to delete all files that older than 10 days from airflow sub folders



I used the following command:



 find /var/log/airflow/ -type f -mtime +10 -delete


but excluding all the files that exist under airflow folder as: file1 , file2 , file3 , file4 , file5



pwd

/var/log/airflow

ls -ltr

drwxr-xr-x 2 root root 6 Sep 13 11:15 folder1
drwxr-xr-x 2 root root 6 Sep 13 11:15 folder2
drwxr-xr-x 2 root root 6 Sep 13 11:15 folder3
drwxr-xr-x 2 root root 6 Sep 13 11:15 folder4
drwxr-xr-x 2 root root 6 Sep 13 11:15 folder5
-rw-r--r-- 1 root root 0 Sep 13 11:15 file1
-rw-r--r-- 1 root root 0 Sep 13 11:15 file2
-rw-r--r-- 1 root root 0 Sep 13 11:15 file3
-rw-r--r-- 1 root root 0 Sep 13 11:15 file4
-rw-r--r-- 1 root root 0 Sep 13 11:15 file5


so all sub folders under airflow with their files will be effaced but not the files under airflow. In that case how can I change my command to support the excluding.










share|improve this question



























    up vote
    0
    down vote

    favorite












    I would like to delete all files that older than 10 days from airflow sub folders



    I used the following command:



     find /var/log/airflow/ -type f -mtime +10 -delete


    but excluding all the files that exist under airflow folder as: file1 , file2 , file3 , file4 , file5



    pwd

    /var/log/airflow

    ls -ltr

    drwxr-xr-x 2 root root 6 Sep 13 11:15 folder1
    drwxr-xr-x 2 root root 6 Sep 13 11:15 folder2
    drwxr-xr-x 2 root root 6 Sep 13 11:15 folder3
    drwxr-xr-x 2 root root 6 Sep 13 11:15 folder4
    drwxr-xr-x 2 root root 6 Sep 13 11:15 folder5
    -rw-r--r-- 1 root root 0 Sep 13 11:15 file1
    -rw-r--r-- 1 root root 0 Sep 13 11:15 file2
    -rw-r--r-- 1 root root 0 Sep 13 11:15 file3
    -rw-r--r-- 1 root root 0 Sep 13 11:15 file4
    -rw-r--r-- 1 root root 0 Sep 13 11:15 file5


    so all sub folders under airflow with their files will be effaced but not the files under airflow. In that case how can I change my command to support the excluding.










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I would like to delete all files that older than 10 days from airflow sub folders



      I used the following command:



       find /var/log/airflow/ -type f -mtime +10 -delete


      but excluding all the files that exist under airflow folder as: file1 , file2 , file3 , file4 , file5



      pwd

      /var/log/airflow

      ls -ltr

      drwxr-xr-x 2 root root 6 Sep 13 11:15 folder1
      drwxr-xr-x 2 root root 6 Sep 13 11:15 folder2
      drwxr-xr-x 2 root root 6 Sep 13 11:15 folder3
      drwxr-xr-x 2 root root 6 Sep 13 11:15 folder4
      drwxr-xr-x 2 root root 6 Sep 13 11:15 folder5
      -rw-r--r-- 1 root root 0 Sep 13 11:15 file1
      -rw-r--r-- 1 root root 0 Sep 13 11:15 file2
      -rw-r--r-- 1 root root 0 Sep 13 11:15 file3
      -rw-r--r-- 1 root root 0 Sep 13 11:15 file4
      -rw-r--r-- 1 root root 0 Sep 13 11:15 file5


      so all sub folders under airflow with their files will be effaced but not the files under airflow. In that case how can I change my command to support the excluding.










      share|improve this question















      I would like to delete all files that older than 10 days from airflow sub folders



      I used the following command:



       find /var/log/airflow/ -type f -mtime +10 -delete


      but excluding all the files that exist under airflow folder as: file1 , file2 , file3 , file4 , file5



      pwd

      /var/log/airflow

      ls -ltr

      drwxr-xr-x 2 root root 6 Sep 13 11:15 folder1
      drwxr-xr-x 2 root root 6 Sep 13 11:15 folder2
      drwxr-xr-x 2 root root 6 Sep 13 11:15 folder3
      drwxr-xr-x 2 root root 6 Sep 13 11:15 folder4
      drwxr-xr-x 2 root root 6 Sep 13 11:15 folder5
      -rw-r--r-- 1 root root 0 Sep 13 11:15 file1
      -rw-r--r-- 1 root root 0 Sep 13 11:15 file2
      -rw-r--r-- 1 root root 0 Sep 13 11:15 file3
      -rw-r--r-- 1 root root 0 Sep 13 11:15 file4
      -rw-r--r-- 1 root root 0 Sep 13 11:15 file5


      so all sub folders under airflow with their files will be effaced but not the files under airflow. In that case how can I change my command to support the excluding.







      linux shell-script rhel find regular-expression






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 13 at 14:38









      Goro

      5,47052460




      5,47052460










      asked Sep 13 at 11:20









      yael

      2,0391345




      2,0391345




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          all you need to do is add the -mindepth global option like this:



          $ find /var/log/airflow/ -mindepth 2 -type f -mtime +10 -delete





          share|improve this answer



























            up vote
            0
            down vote













            To tell find to look only in subfolders of /var/log/airflow, just give it those starting points:



            shopt -s dotglob
            find /var/log/airflow/*/* -type f -mtime +10 -delete


            This forces a subdirectory to exist under /var/log/airflow in order to match. I set dotglob so that any "hidden" directories under airflow are also matched.






            share|improve this answer




















              Your Answer







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

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

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f468769%2fdeleting-files-older-than-a-specific-day-and-excluding-the-direct-files-under-fo%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              3
              down vote



              accepted










              all you need to do is add the -mindepth global option like this:



              $ find /var/log/airflow/ -mindepth 2 -type f -mtime +10 -delete





              share|improve this answer
























                up vote
                3
                down vote



                accepted










                all you need to do is add the -mindepth global option like this:



                $ find /var/log/airflow/ -mindepth 2 -type f -mtime +10 -delete





                share|improve this answer






















                  up vote
                  3
                  down vote



                  accepted







                  up vote
                  3
                  down vote



                  accepted






                  all you need to do is add the -mindepth global option like this:



                  $ find /var/log/airflow/ -mindepth 2 -type f -mtime +10 -delete





                  share|improve this answer












                  all you need to do is add the -mindepth global option like this:



                  $ find /var/log/airflow/ -mindepth 2 -type f -mtime +10 -delete






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 13 at 11:45









                  B.McCready

                  663




                  663






















                      up vote
                      0
                      down vote













                      To tell find to look only in subfolders of /var/log/airflow, just give it those starting points:



                      shopt -s dotglob
                      find /var/log/airflow/*/* -type f -mtime +10 -delete


                      This forces a subdirectory to exist under /var/log/airflow in order to match. I set dotglob so that any "hidden" directories under airflow are also matched.






                      share|improve this answer
























                        up vote
                        0
                        down vote













                        To tell find to look only in subfolders of /var/log/airflow, just give it those starting points:



                        shopt -s dotglob
                        find /var/log/airflow/*/* -type f -mtime +10 -delete


                        This forces a subdirectory to exist under /var/log/airflow in order to match. I set dotglob so that any "hidden" directories under airflow are also matched.






                        share|improve this answer






















                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          To tell find to look only in subfolders of /var/log/airflow, just give it those starting points:



                          shopt -s dotglob
                          find /var/log/airflow/*/* -type f -mtime +10 -delete


                          This forces a subdirectory to exist under /var/log/airflow in order to match. I set dotglob so that any "hidden" directories under airflow are also matched.






                          share|improve this answer












                          To tell find to look only in subfolders of /var/log/airflow, just give it those starting points:



                          shopt -s dotglob
                          find /var/log/airflow/*/* -type f -mtime +10 -delete


                          This forces a subdirectory to exist under /var/log/airflow in order to match. I set dotglob so that any "hidden" directories under airflow are also matched.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Sep 13 at 12:33









                          Jeff Schaller

                          33.1k849111




                          33.1k849111



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f468769%2fdeleting-files-older-than-a-specific-day-and-excluding-the-direct-files-under-fo%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Popular posts from this blog

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

                              Displaying single band from multi-band raster using QGIS

                              How many registers does an x86_64 CPU actually have?