delete files older than 10 days and store the deleted file details in another file





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-1















I want to delete directories and subdirectories older than 10 days.



Also, I want to store the deleted folder and file names, time details in another file.



So far my script is to delete directories, subdirectories, and file which is older than 10 days.



find /tmp/processed/* -type d -ctime +10 -exec rm -rf {} ;


Could some one help to store the details in another file?



Thanks in advance.










share|improve this question





























    -1















    I want to delete directories and subdirectories older than 10 days.



    Also, I want to store the deleted folder and file names, time details in another file.



    So far my script is to delete directories, subdirectories, and file which is older than 10 days.



    find /tmp/processed/* -type d -ctime +10 -exec rm -rf {} ;


    Could some one help to store the details in another file?



    Thanks in advance.










    share|improve this question

























      -1












      -1








      -1








      I want to delete directories and subdirectories older than 10 days.



      Also, I want to store the deleted folder and file names, time details in another file.



      So far my script is to delete directories, subdirectories, and file which is older than 10 days.



      find /tmp/processed/* -type d -ctime +10 -exec rm -rf {} ;


      Could some one help to store the details in another file?



      Thanks in advance.










      share|improve this question














      I want to delete directories and subdirectories older than 10 days.



      Also, I want to store the deleted folder and file names, time details in another file.



      So far my script is to delete directories, subdirectories, and file which is older than 10 days.



      find /tmp/processed/* -type d -ctime +10 -exec rm -rf {} ;


      Could some one help to store the details in another file?



      Thanks in advance.







      linux bash unix script shell-script






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 6 at 10:39









      AnjanaaAnjanaa

      1




      1






















          2 Answers
          2






          active

          oldest

          votes


















          0














          You need to save details of files and folders before deleting. For example



          find /tmp/processed/* -ctime +10 -printf "%p %TY-%Tm-%Td %TH:%TM:%TS %Tzn" >> ~/DeletedFiles.txt



          See this answer more formatting options https://stackoverflow.com/questions/20893022/how-to-display-modified-date-time-with-find-command






          share|improve this answer































            0














            You can run multiple commands at the same time:



            find /tmp/processed/* -type d -ctime +10 -print -exec rm -rf {} ;


            You can use the information that @Ix07 posted in their answer:



            find /tmp/processed/* -type d -ctime +10 -printf "%p %TY-%Tm-%Td %TH:%TM:%TS %TZn" -exec rm -rf {} ;


            You can redirect the output of this to a file.

            Note, however, that this can give quite messy (unaligned) output when viewing. As such, I like to use the column command in combination with tabs in the printf format to 'tablify' the data:



            find /tmp/processed/* -type d -ctime +10 -printf "%pt%TY-%Tm-%Tdt%TH:%TM:%TSt%TZn" -exec rm -rf {} ; | column -t


            I tested the output of the above, and it looked like this for me:



            /tmp/processed $ find * -type d -ctime +10 -printf "%pt%TY-%Tm-%Tdt%TH:%TM:%TSt%TZn" -exec rm -rf {} ; | column -t
            bar 2019-02-07 20:35:15.8718172190 WAT
            foo 2019-02-07 20:35:54.5638166540 WAT


            Look at the man page for find to know more (tip: Search in the man page for -printf).






            share|improve this answer
























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "3"
              };
              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: 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%2fsuperuser.com%2fquestions%2f1402613%2fdelete-files-older-than-10-days-and-store-the-deleted-file-details-in-another-fi%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              You need to save details of files and folders before deleting. For example



              find /tmp/processed/* -ctime +10 -printf "%p %TY-%Tm-%Td %TH:%TM:%TS %Tzn" >> ~/DeletedFiles.txt



              See this answer more formatting options https://stackoverflow.com/questions/20893022/how-to-display-modified-date-time-with-find-command






              share|improve this answer




























                0














                You need to save details of files and folders before deleting. For example



                find /tmp/processed/* -ctime +10 -printf "%p %TY-%Tm-%Td %TH:%TM:%TS %Tzn" >> ~/DeletedFiles.txt



                See this answer more formatting options https://stackoverflow.com/questions/20893022/how-to-display-modified-date-time-with-find-command






                share|improve this answer


























                  0












                  0








                  0







                  You need to save details of files and folders before deleting. For example



                  find /tmp/processed/* -ctime +10 -printf "%p %TY-%Tm-%Td %TH:%TM:%TS %Tzn" >> ~/DeletedFiles.txt



                  See this answer more formatting options https://stackoverflow.com/questions/20893022/how-to-display-modified-date-time-with-find-command






                  share|improve this answer













                  You need to save details of files and folders before deleting. For example



                  find /tmp/processed/* -ctime +10 -printf "%p %TY-%Tm-%Td %TH:%TM:%TS %Tzn" >> ~/DeletedFiles.txt



                  See this answer more formatting options https://stackoverflow.com/questions/20893022/how-to-display-modified-date-time-with-find-command







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 6 at 12:17









                  lx07lx07

                  646411




                  646411

























                      0














                      You can run multiple commands at the same time:



                      find /tmp/processed/* -type d -ctime +10 -print -exec rm -rf {} ;


                      You can use the information that @Ix07 posted in their answer:



                      find /tmp/processed/* -type d -ctime +10 -printf "%p %TY-%Tm-%Td %TH:%TM:%TS %TZn" -exec rm -rf {} ;


                      You can redirect the output of this to a file.

                      Note, however, that this can give quite messy (unaligned) output when viewing. As such, I like to use the column command in combination with tabs in the printf format to 'tablify' the data:



                      find /tmp/processed/* -type d -ctime +10 -printf "%pt%TY-%Tm-%Tdt%TH:%TM:%TSt%TZn" -exec rm -rf {} ; | column -t


                      I tested the output of the above, and it looked like this for me:



                      /tmp/processed $ find * -type d -ctime +10 -printf "%pt%TY-%Tm-%Tdt%TH:%TM:%TSt%TZn" -exec rm -rf {} ; | column -t
                      bar 2019-02-07 20:35:15.8718172190 WAT
                      foo 2019-02-07 20:35:54.5638166540 WAT


                      Look at the man page for find to know more (tip: Search in the man page for -printf).






                      share|improve this answer




























                        0














                        You can run multiple commands at the same time:



                        find /tmp/processed/* -type d -ctime +10 -print -exec rm -rf {} ;


                        You can use the information that @Ix07 posted in their answer:



                        find /tmp/processed/* -type d -ctime +10 -printf "%p %TY-%Tm-%Td %TH:%TM:%TS %TZn" -exec rm -rf {} ;


                        You can redirect the output of this to a file.

                        Note, however, that this can give quite messy (unaligned) output when viewing. As such, I like to use the column command in combination with tabs in the printf format to 'tablify' the data:



                        find /tmp/processed/* -type d -ctime +10 -printf "%pt%TY-%Tm-%Tdt%TH:%TM:%TSt%TZn" -exec rm -rf {} ; | column -t


                        I tested the output of the above, and it looked like this for me:



                        /tmp/processed $ find * -type d -ctime +10 -printf "%pt%TY-%Tm-%Tdt%TH:%TM:%TSt%TZn" -exec rm -rf {} ; | column -t
                        bar 2019-02-07 20:35:15.8718172190 WAT
                        foo 2019-02-07 20:35:54.5638166540 WAT


                        Look at the man page for find to know more (tip: Search in the man page for -printf).






                        share|improve this answer


























                          0












                          0








                          0







                          You can run multiple commands at the same time:



                          find /tmp/processed/* -type d -ctime +10 -print -exec rm -rf {} ;


                          You can use the information that @Ix07 posted in their answer:



                          find /tmp/processed/* -type d -ctime +10 -printf "%p %TY-%Tm-%Td %TH:%TM:%TS %TZn" -exec rm -rf {} ;


                          You can redirect the output of this to a file.

                          Note, however, that this can give quite messy (unaligned) output when viewing. As such, I like to use the column command in combination with tabs in the printf format to 'tablify' the data:



                          find /tmp/processed/* -type d -ctime +10 -printf "%pt%TY-%Tm-%Tdt%TH:%TM:%TSt%TZn" -exec rm -rf {} ; | column -t


                          I tested the output of the above, and it looked like this for me:



                          /tmp/processed $ find * -type d -ctime +10 -printf "%pt%TY-%Tm-%Tdt%TH:%TM:%TSt%TZn" -exec rm -rf {} ; | column -t
                          bar 2019-02-07 20:35:15.8718172190 WAT
                          foo 2019-02-07 20:35:54.5638166540 WAT


                          Look at the man page for find to know more (tip: Search in the man page for -printf).






                          share|improve this answer













                          You can run multiple commands at the same time:



                          find /tmp/processed/* -type d -ctime +10 -print -exec rm -rf {} ;


                          You can use the information that @Ix07 posted in their answer:



                          find /tmp/processed/* -type d -ctime +10 -printf "%p %TY-%Tm-%Td %TH:%TM:%TS %TZn" -exec rm -rf {} ;


                          You can redirect the output of this to a file.

                          Note, however, that this can give quite messy (unaligned) output when viewing. As such, I like to use the column command in combination with tabs in the printf format to 'tablify' the data:



                          find /tmp/processed/* -type d -ctime +10 -printf "%pt%TY-%Tm-%Tdt%TH:%TM:%TSt%TZn" -exec rm -rf {} ; | column -t


                          I tested the output of the above, and it looked like this for me:



                          /tmp/processed $ find * -type d -ctime +10 -printf "%pt%TY-%Tm-%Tdt%TH:%TM:%TSt%TZn" -exec rm -rf {} ; | column -t
                          bar 2019-02-07 20:35:15.8718172190 WAT
                          foo 2019-02-07 20:35:54.5638166540 WAT


                          Look at the man page for find to know more (tip: Search in the man page for -printf).







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Feb 7 at 19:38









                          ARaspiKARaspiK

                          262




                          262






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Super User!


                              • 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%2fsuperuser.com%2fquestions%2f1402613%2fdelete-files-older-than-10-days-and-store-the-deleted-file-details-in-another-fi%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

                              Plaza Victoria

                              Brian Clough

                              Cáceres