how to echo find command












0














For a raspberry backup bash-script I want to log which and how many older backups are deleted.



I use



find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete


to clean.



How do I count and display and log to a file which files are deleted?










share|improve this question









New contributor




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

























    0














    For a raspberry backup bash-script I want to log which and how many older backups are deleted.



    I use



    find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete


    to clean.



    How do I count and display and log to a file which files are deleted?










    share|improve this question









    New contributor




    Thuurke 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







      For a raspberry backup bash-script I want to log which and how many older backups are deleted.



      I use



      find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete


      to clean.



      How do I count and display and log to a file which files are deleted?










      share|improve this question









      New contributor




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











      For a raspberry backup bash-script I want to log which and how many older backups are deleted.



      I use



      find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete


      to clean.



      How do I count and display and log to a file which files are deleted?







      bash find






      share|improve this question









      New contributor




      Thuurke 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 question









      New contributor




      Thuurke 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 question




      share|improve this question








      edited 1 hour ago









      Thomas

      3,70061225




      3,70061225






      New contributor




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









      asked 1 hour ago









      Thuurke

      1




      1




      New contributor




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





      New contributor





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






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






















          2 Answers
          2






          active

          oldest

          votes


















          2














          find has an fprint action that can write the results of the find command to a file. You can then extend your command as:



          find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -fprint /path/to/log.txt -delete


          You can then retrieve the file count from the log file, by using wc:



          cat /path/to/log.txt | wc -l


          If special characters can appear in the results of find, you can use the the fprint0 option as an alternative. This will write the results to the specified file as null-delimited strings.



          To count the items in the resulting file, you can look the options discussed under this question: Count null delimited items in file.






          share|improve this answer



















          • 1




            Not all implementations of find support fprint, GNU find does but busybox for example does not. It's also not mandated by POSIX: pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html. And you don't need cat to count number of lines with wc: wc -l <FILE> is enough.
            – Arkadiusz Drabczyk
            1 hour ago










          • @ArkadiuszDrabczyk Thanks for the information on POSIX find. Regarding the usage of cat, I used it so that the output is only a number. wc shows the filename beside the count with the wc -l file syntax.
            – Haxiel
            54 mins ago



















          1














          You can use the -print option of find, to output the files that are deleted, then pipe things to tee to write results into a logfile. And finally count the lines of the deleted files and append it in the logfile.



          find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete -print | tee ${LOGFILE} | wc -l | xargs echo "Files deleted:" >> ${LOGFILE}


          If you want to append new results to the same ${LOGFILE} you would have to use tee -a.






          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',
            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
            });


            }
            });






            Thuurke is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491302%2fhow-to-echo-find-command%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









            2














            find has an fprint action that can write the results of the find command to a file. You can then extend your command as:



            find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -fprint /path/to/log.txt -delete


            You can then retrieve the file count from the log file, by using wc:



            cat /path/to/log.txt | wc -l


            If special characters can appear in the results of find, you can use the the fprint0 option as an alternative. This will write the results to the specified file as null-delimited strings.



            To count the items in the resulting file, you can look the options discussed under this question: Count null delimited items in file.






            share|improve this answer



















            • 1




              Not all implementations of find support fprint, GNU find does but busybox for example does not. It's also not mandated by POSIX: pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html. And you don't need cat to count number of lines with wc: wc -l <FILE> is enough.
              – Arkadiusz Drabczyk
              1 hour ago










            • @ArkadiuszDrabczyk Thanks for the information on POSIX find. Regarding the usage of cat, I used it so that the output is only a number. wc shows the filename beside the count with the wc -l file syntax.
              – Haxiel
              54 mins ago
















            2














            find has an fprint action that can write the results of the find command to a file. You can then extend your command as:



            find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -fprint /path/to/log.txt -delete


            You can then retrieve the file count from the log file, by using wc:



            cat /path/to/log.txt | wc -l


            If special characters can appear in the results of find, you can use the the fprint0 option as an alternative. This will write the results to the specified file as null-delimited strings.



            To count the items in the resulting file, you can look the options discussed under this question: Count null delimited items in file.






            share|improve this answer



















            • 1




              Not all implementations of find support fprint, GNU find does but busybox for example does not. It's also not mandated by POSIX: pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html. And you don't need cat to count number of lines with wc: wc -l <FILE> is enough.
              – Arkadiusz Drabczyk
              1 hour ago










            • @ArkadiuszDrabczyk Thanks for the information on POSIX find. Regarding the usage of cat, I used it so that the output is only a number. wc shows the filename beside the count with the wc -l file syntax.
              – Haxiel
              54 mins ago














            2












            2








            2






            find has an fprint action that can write the results of the find command to a file. You can then extend your command as:



            find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -fprint /path/to/log.txt -delete


            You can then retrieve the file count from the log file, by using wc:



            cat /path/to/log.txt | wc -l


            If special characters can appear in the results of find, you can use the the fprint0 option as an alternative. This will write the results to the specified file as null-delimited strings.



            To count the items in the resulting file, you can look the options discussed under this question: Count null delimited items in file.






            share|improve this answer














            find has an fprint action that can write the results of the find command to a file. You can then extend your command as:



            find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -fprint /path/to/log.txt -delete


            You can then retrieve the file count from the log file, by using wc:



            cat /path/to/log.txt | wc -l


            If special characters can appear in the results of find, you can use the the fprint0 option as an alternative. This will write the results to the specified file as null-delimited strings.



            To count the items in the resulting file, you can look the options discussed under this question: Count null delimited items in file.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 58 mins ago

























            answered 1 hour ago









            Haxiel

            1,099310




            1,099310








            • 1




              Not all implementations of find support fprint, GNU find does but busybox for example does not. It's also not mandated by POSIX: pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html. And you don't need cat to count number of lines with wc: wc -l <FILE> is enough.
              – Arkadiusz Drabczyk
              1 hour ago










            • @ArkadiuszDrabczyk Thanks for the information on POSIX find. Regarding the usage of cat, I used it so that the output is only a number. wc shows the filename beside the count with the wc -l file syntax.
              – Haxiel
              54 mins ago














            • 1




              Not all implementations of find support fprint, GNU find does but busybox for example does not. It's also not mandated by POSIX: pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html. And you don't need cat to count number of lines with wc: wc -l <FILE> is enough.
              – Arkadiusz Drabczyk
              1 hour ago










            • @ArkadiuszDrabczyk Thanks for the information on POSIX find. Regarding the usage of cat, I used it so that the output is only a number. wc shows the filename beside the count with the wc -l file syntax.
              – Haxiel
              54 mins ago








            1




            1




            Not all implementations of find support fprint, GNU find does but busybox for example does not. It's also not mandated by POSIX: pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html. And you don't need cat to count number of lines with wc: wc -l <FILE> is enough.
            – Arkadiusz Drabczyk
            1 hour ago




            Not all implementations of find support fprint, GNU find does but busybox for example does not. It's also not mandated by POSIX: pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html. And you don't need cat to count number of lines with wc: wc -l <FILE> is enough.
            – Arkadiusz Drabczyk
            1 hour ago












            @ArkadiuszDrabczyk Thanks for the information on POSIX find. Regarding the usage of cat, I used it so that the output is only a number. wc shows the filename beside the count with the wc -l file syntax.
            – Haxiel
            54 mins ago




            @ArkadiuszDrabczyk Thanks for the information on POSIX find. Regarding the usage of cat, I used it so that the output is only a number. wc shows the filename beside the count with the wc -l file syntax.
            – Haxiel
            54 mins ago













            1














            You can use the -print option of find, to output the files that are deleted, then pipe things to tee to write results into a logfile. And finally count the lines of the deleted files and append it in the logfile.



            find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete -print | tee ${LOGFILE} | wc -l | xargs echo "Files deleted:" >> ${LOGFILE}


            If you want to append new results to the same ${LOGFILE} you would have to use tee -a.






            share|improve this answer


























              1














              You can use the -print option of find, to output the files that are deleted, then pipe things to tee to write results into a logfile. And finally count the lines of the deleted files and append it in the logfile.



              find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete -print | tee ${LOGFILE} | wc -l | xargs echo "Files deleted:" >> ${LOGFILE}


              If you want to append new results to the same ${LOGFILE} you would have to use tee -a.






              share|improve this answer
























                1












                1








                1






                You can use the -print option of find, to output the files that are deleted, then pipe things to tee to write results into a logfile. And finally count the lines of the deleted files and append it in the logfile.



                find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete -print | tee ${LOGFILE} | wc -l | xargs echo "Files deleted:" >> ${LOGFILE}


                If you want to append new results to the same ${LOGFILE} you would have to use tee -a.






                share|improve this answer












                You can use the -print option of find, to output the files that are deleted, then pipe things to tee to write results into a logfile. And finally count the lines of the deleted files and append it in the logfile.



                find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete -print | tee ${LOGFILE} | wc -l | xargs echo "Files deleted:" >> ${LOGFILE}


                If you want to append new results to the same ${LOGFILE} you would have to use tee -a.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 44 mins ago









                Thomas

                3,70061225




                3,70061225






















                    Thuurke is a new contributor. Be nice, and check out our Code of Conduct.










                    draft saved

                    draft discarded


















                    Thuurke is a new contributor. Be nice, and check out our Code of Conduct.













                    Thuurke is a new contributor. Be nice, and check out our Code of Conduct.












                    Thuurke is a new contributor. Be nice, and check out our Code of Conduct.
















                    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.





                    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%2funix.stackexchange.com%2fquestions%2f491302%2fhow-to-echo-find-command%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

                    サソリ

                    広島県道265号伴広島線

                    Accessing regular linux commands in Huawei's Dopra Linux