Linux: find files *.log in directory trees and write 10 last lines in each

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











up vote
0
down vote

favorite












I need to find all files, that ends with .log in directory /var and all its trees-directories; and to write ten last lines of each of these *.log files




cd /var
sudo find -name '*.log' -print




This command allows me to find these files. What I see is:

./log/auth.log
./log/Xorg.0.log
....
./log/apt/term.log
.log/alternatives.log

I've tried to use
for var in sudo find -name '*.log'; do tail -n 10 $var; done to print the lines, but there was an error. So what command should I use in order to find files and print the lines?










share|improve this question

























    up vote
    0
    down vote

    favorite












    I need to find all files, that ends with .log in directory /var and all its trees-directories; and to write ten last lines of each of these *.log files




    cd /var
    sudo find -name '*.log' -print




    This command allows me to find these files. What I see is:

    ./log/auth.log
    ./log/Xorg.0.log
    ....
    ./log/apt/term.log
    .log/alternatives.log

    I've tried to use
    for var in sudo find -name '*.log'; do tail -n 10 $var; done to print the lines, but there was an error. So what command should I use in order to find files and print the lines?










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I need to find all files, that ends with .log in directory /var and all its trees-directories; and to write ten last lines of each of these *.log files




      cd /var
      sudo find -name '*.log' -print




      This command allows me to find these files. What I see is:

      ./log/auth.log
      ./log/Xorg.0.log
      ....
      ./log/apt/term.log
      .log/alternatives.log

      I've tried to use
      for var in sudo find -name '*.log'; do tail -n 10 $var; done to print the lines, but there was an error. So what command should I use in order to find files and print the lines?










      share|improve this question













      I need to find all files, that ends with .log in directory /var and all its trees-directories; and to write ten last lines of each of these *.log files




      cd /var
      sudo find -name '*.log' -print




      This command allows me to find these files. What I see is:

      ./log/auth.log
      ./log/Xorg.0.log
      ....
      ./log/apt/term.log
      .log/alternatives.log

      I've tried to use
      for var in sudo find -name '*.log'; do tail -n 10 $var; done to print the lines, but there was an error. So what command should I use in order to find files and print the lines?







      linux






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Oct 1 '17 at 16:40









      Николай Журба

      285




      285




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          Try this:



          find /var -name "*.log" -type f -exec tail '' +


          Explanation:



          -type f - find only files



          -exec <command> + - execute command. See man find for more information



          Or:



          for i in $(find /var -name "*.log" -type f); do echo $i; tail $i; done


          Gets the same output but with slight format difference






          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%2f395485%2flinux-find-files-log-in-directory-trees-and-write-10-last-lines-in-each%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote



            accepted










            Try this:



            find /var -name "*.log" -type f -exec tail '' +


            Explanation:



            -type f - find only files



            -exec <command> + - execute command. See man find for more information



            Or:



            for i in $(find /var -name "*.log" -type f); do echo $i; tail $i; done


            Gets the same output but with slight format difference






            share|improve this answer


























              up vote
              2
              down vote



              accepted










              Try this:



              find /var -name "*.log" -type f -exec tail '' +


              Explanation:



              -type f - find only files



              -exec <command> + - execute command. See man find for more information



              Or:



              for i in $(find /var -name "*.log" -type f); do echo $i; tail $i; done


              Gets the same output but with slight format difference






              share|improve this answer
























                up vote
                2
                down vote



                accepted







                up vote
                2
                down vote



                accepted






                Try this:



                find /var -name "*.log" -type f -exec tail '' +


                Explanation:



                -type f - find only files



                -exec <command> + - execute command. See man find for more information



                Or:



                for i in $(find /var -name "*.log" -type f); do echo $i; tail $i; done


                Gets the same output but with slight format difference






                share|improve this answer














                Try this:



                find /var -name "*.log" -type f -exec tail '' +


                Explanation:



                -type f - find only files



                -exec <command> + - execute command. See man find for more information



                Or:



                for i in $(find /var -name "*.log" -type f); do echo $i; tail $i; done


                Gets the same output but with slight format difference







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Oct 1 '17 at 16:51

























                answered Oct 1 '17 at 16:44









                Egor Vasilyev

                1,792129




                1,792129



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f395485%2flinux-find-files-log-in-directory-trees-and-write-10-last-lines-in-each%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?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay