Capture log files that ended with any number

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











up vote
-1
down vote

favorite












We want to capture all logs that ended with ".log.[any number]



So I create this syntax



find . -type f -regex '^.log.*[0-9]$' -print

command does not give any output


But this doesn't capture the files as the following ( expected results )



 controller.log.2018-01-03-01 
server.log.2017-10-31-03
server.log.2018-01-23-11
server.log.2018-04-06-17
server.log.2018-07-07-05
controller.log.2018-01-03-02
log-cleaner.log.10
server.log.2017-10-31-04
server.log.2018-01-23-12
server.log.2018-04-06-18
server.log.2018-07-07-06
controller.log.2018-01-03-03
log-cleaner.log.2
server.log.232.434


what is wrong with my syntax ?










share|improve this question























  • why do we use ^ and . should be escaped
    – msp9011
    Aug 29 at 10:14






  • 1




    Why use a regex? find /var/log -type f -name *.log.*[0-9] No escaping of dots needed, etc. If you want to find Logs LOGS and logs, then change the -name to -iname
    – ivanivan
    Aug 29 at 21:53














up vote
-1
down vote

favorite












We want to capture all logs that ended with ".log.[any number]



So I create this syntax



find . -type f -regex '^.log.*[0-9]$' -print

command does not give any output


But this doesn't capture the files as the following ( expected results )



 controller.log.2018-01-03-01 
server.log.2017-10-31-03
server.log.2018-01-23-11
server.log.2018-04-06-17
server.log.2018-07-07-05
controller.log.2018-01-03-02
log-cleaner.log.10
server.log.2017-10-31-04
server.log.2018-01-23-12
server.log.2018-04-06-18
server.log.2018-07-07-06
controller.log.2018-01-03-03
log-cleaner.log.2
server.log.232.434


what is wrong with my syntax ?










share|improve this question























  • why do we use ^ and . should be escaped
    – msp9011
    Aug 29 at 10:14






  • 1




    Why use a regex? find /var/log -type f -name *.log.*[0-9] No escaping of dots needed, etc. If you want to find Logs LOGS and logs, then change the -name to -iname
    – ivanivan
    Aug 29 at 21:53












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











We want to capture all logs that ended with ".log.[any number]



So I create this syntax



find . -type f -regex '^.log.*[0-9]$' -print

command does not give any output


But this doesn't capture the files as the following ( expected results )



 controller.log.2018-01-03-01 
server.log.2017-10-31-03
server.log.2018-01-23-11
server.log.2018-04-06-17
server.log.2018-07-07-05
controller.log.2018-01-03-02
log-cleaner.log.10
server.log.2017-10-31-04
server.log.2018-01-23-12
server.log.2018-04-06-18
server.log.2018-07-07-06
controller.log.2018-01-03-03
log-cleaner.log.2
server.log.232.434


what is wrong with my syntax ?










share|improve this question















We want to capture all logs that ended with ".log.[any number]



So I create this syntax



find . -type f -regex '^.log.*[0-9]$' -print

command does not give any output


But this doesn't capture the files as the following ( expected results )



 controller.log.2018-01-03-01 
server.log.2017-10-31-03
server.log.2018-01-23-11
server.log.2018-04-06-17
server.log.2018-07-07-05
controller.log.2018-01-03-02
log-cleaner.log.10
server.log.2017-10-31-04
server.log.2018-01-23-12
server.log.2018-04-06-18
server.log.2018-07-07-06
controller.log.2018-01-03-03
log-cleaner.log.2
server.log.232.434


what is wrong with my syntax ?







linux files find regular-expression






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 29 at 10:42









msp9011

3,46643862




3,46643862










asked Aug 29 at 9:26









yael

2,0391245




2,0391245











  • why do we use ^ and . should be escaped
    – msp9011
    Aug 29 at 10:14






  • 1




    Why use a regex? find /var/log -type f -name *.log.*[0-9] No escaping of dots needed, etc. If you want to find Logs LOGS and logs, then change the -name to -iname
    – ivanivan
    Aug 29 at 21:53
















  • why do we use ^ and . should be escaped
    – msp9011
    Aug 29 at 10:14






  • 1




    Why use a regex? find /var/log -type f -name *.log.*[0-9] No escaping of dots needed, etc. If you want to find Logs LOGS and logs, then change the -name to -iname
    – ivanivan
    Aug 29 at 21:53















why do we use ^ and . should be escaped
– msp9011
Aug 29 at 10:14




why do we use ^ and . should be escaped
– msp9011
Aug 29 at 10:14




1




1




Why use a regex? find /var/log -type f -name *.log.*[0-9] No escaping of dots needed, etc. If you want to find Logs LOGS and logs, then change the -name to -iname
– ivanivan
Aug 29 at 21:53




Why use a regex? find /var/log -type f -name *.log.*[0-9] No escaping of dots needed, etc. If you want to find Logs LOGS and logs, then change the -name to -iname
– ivanivan
Aug 29 at 21:53










4 Answers
4






active

oldest

votes

















up vote
1
down vote



accepted










-regex (a GNU extension also recognised by some other find implementations nowadays but with major differences) is like -path except that it uses regexps instead of wildcards. It matches on the whole file path, not just its name.



So .*.log.*[0-9] (no need for ^ or $ by the way, they're implicit with find's -regex) would match on ./dir/foo.log-3 but also ./foo.logic/file.bz2, where the .* captured ic/file.bz.



-name matches on the file name only, uses wildcards but doesn't have a regexp counterpart. Here, for files whose name contain .log and end in a digit, you don't need regexps anyway, -name '*.foo*[0-9]'.



You can do the same with regexps though with -regex '.*.log[^/]*[0-9]', that is making sure the part between .log and the final digit doesn't contain any / so it matches on the file name only.



With -regex, you can go further in specifying the patterns, especially if you enable extended regexps, using -E with some BSD's find or -regextype posix-extended with GNU find.



find . -regextype posix-extended -regex '.*.log([.-][0-9]+)+' # GNU
find -E . -regex '.*.log([.-][0-9]+)+' # BSD


Here matching on .log followed by one or more .<number> or -<number>.



Without -regextype posix-extended GNU find's regexps are emacs regexps, some sort of hybrid between standard basic regexps and standard extended regexps (supports +, but grouping is with (...) instead of (...)).



Without -E BSD find regexps are standard basic regexps.






share|improve this answer



























    up vote
    0
    down vote













    Try,



    find . -type f -regex ".*.log..*[0-9]$"
    ./server.log.2018-01-23-12
    ./server.log.2018-07-07-06
    ./log-cleaner.log.2
    ./log-cleaner.log.10
    ./server.log.232.434
    ./server.log.2018-01-23-11
    ./server.log.2017-10-31-03
    ./controller.log.2018-01-03-01
    ./server.log.2018-04-06-17
    ./log-cleaner.log.1
    ./controller.log.2018-01-03-03
    ./server.log.2018-04-06-18
    ./controller.log.2018-01-03-02
    ./server.log.2018-07-07-05
    ./server.log.2017-10-31-04


    • we need to escape the .





    share|improve this answer




















    • this syntax not works
      – yael
      Aug 29 at 10:31










    • @yeal can you share the error
      – msp9011
      Aug 29 at 10:33










    • it si just print only the file - gc.log.0 , but all other are not printed
      – yael
      Aug 29 at 10:34










    • yes I already did it
      – yael
      Aug 29 at 10:38










    • what you mean ?
      – yael
      Aug 29 at 10:48

















    up vote
    0
    down vote













    If after "log" there's only digits, ., and -, the following might work as well



    find . -type f -regex ".*[.]log[-.0-9]*$" 





    share|improve this answer



























      up vote
      0
      down vote













      You could search for your files using the following way without recourse to non-GNU find:



      find . -type f 
      ( -name '?*.log.[0-9]' -o
      (
      -name '?*.log.[0-9]*[0-9]'
      ! -name '?*.log.?*[!0-9.-]*?'
      ! -name '?*.log.?*[.-][.-]*?'
      )
      )
      -print;


      What this does is do a multi-layered filtering of the filenames caught by it and progressively shrinks the catch and zeroes in on the required. To be precise:



      • Right away select any file whose basename, i.e., w/o it's path ends in a .log.single_digit

      • OTW, select those that end in .log. NUM anything NUM This will set the trend for the filenames to be caught in the net.

      • Out of the above catch, reject those which happen to have a non number, non dash, or non dot in the anything portion of the filename. Note the trend of beginning and ending with a digit must be honored.

      • Now our catch has all those files in which anything portion comprises only digit(s), dot(s), and dash(s). The last constraint is that the dot or dash must not have each as their immediate neighbors to both their left and right.

      • P.S. Note that -name option looks at the basename portion of the filename only, AND


      • -name portion operates on the wildcard basis and hence they are implicitly anchored, meaning the name matched is full.





      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%2f465459%2fcapture-log-files-that-ended-with-any-number%23new-answer', 'question_page');

        );

        Post as a guest






























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        1
        down vote



        accepted










        -regex (a GNU extension also recognised by some other find implementations nowadays but with major differences) is like -path except that it uses regexps instead of wildcards. It matches on the whole file path, not just its name.



        So .*.log.*[0-9] (no need for ^ or $ by the way, they're implicit with find's -regex) would match on ./dir/foo.log-3 but also ./foo.logic/file.bz2, where the .* captured ic/file.bz.



        -name matches on the file name only, uses wildcards but doesn't have a regexp counterpart. Here, for files whose name contain .log and end in a digit, you don't need regexps anyway, -name '*.foo*[0-9]'.



        You can do the same with regexps though with -regex '.*.log[^/]*[0-9]', that is making sure the part between .log and the final digit doesn't contain any / so it matches on the file name only.



        With -regex, you can go further in specifying the patterns, especially if you enable extended regexps, using -E with some BSD's find or -regextype posix-extended with GNU find.



        find . -regextype posix-extended -regex '.*.log([.-][0-9]+)+' # GNU
        find -E . -regex '.*.log([.-][0-9]+)+' # BSD


        Here matching on .log followed by one or more .<number> or -<number>.



        Without -regextype posix-extended GNU find's regexps are emacs regexps, some sort of hybrid between standard basic regexps and standard extended regexps (supports +, but grouping is with (...) instead of (...)).



        Without -E BSD find regexps are standard basic regexps.






        share|improve this answer
























          up vote
          1
          down vote



          accepted










          -regex (a GNU extension also recognised by some other find implementations nowadays but with major differences) is like -path except that it uses regexps instead of wildcards. It matches on the whole file path, not just its name.



          So .*.log.*[0-9] (no need for ^ or $ by the way, they're implicit with find's -regex) would match on ./dir/foo.log-3 but also ./foo.logic/file.bz2, where the .* captured ic/file.bz.



          -name matches on the file name only, uses wildcards but doesn't have a regexp counterpart. Here, for files whose name contain .log and end in a digit, you don't need regexps anyway, -name '*.foo*[0-9]'.



          You can do the same with regexps though with -regex '.*.log[^/]*[0-9]', that is making sure the part between .log and the final digit doesn't contain any / so it matches on the file name only.



          With -regex, you can go further in specifying the patterns, especially if you enable extended regexps, using -E with some BSD's find or -regextype posix-extended with GNU find.



          find . -regextype posix-extended -regex '.*.log([.-][0-9]+)+' # GNU
          find -E . -regex '.*.log([.-][0-9]+)+' # BSD


          Here matching on .log followed by one or more .<number> or -<number>.



          Without -regextype posix-extended GNU find's regexps are emacs regexps, some sort of hybrid between standard basic regexps and standard extended regexps (supports +, but grouping is with (...) instead of (...)).



          Without -E BSD find regexps are standard basic regexps.






          share|improve this answer






















            up vote
            1
            down vote



            accepted







            up vote
            1
            down vote



            accepted






            -regex (a GNU extension also recognised by some other find implementations nowadays but with major differences) is like -path except that it uses regexps instead of wildcards. It matches on the whole file path, not just its name.



            So .*.log.*[0-9] (no need for ^ or $ by the way, they're implicit with find's -regex) would match on ./dir/foo.log-3 but also ./foo.logic/file.bz2, where the .* captured ic/file.bz.



            -name matches on the file name only, uses wildcards but doesn't have a regexp counterpart. Here, for files whose name contain .log and end in a digit, you don't need regexps anyway, -name '*.foo*[0-9]'.



            You can do the same with regexps though with -regex '.*.log[^/]*[0-9]', that is making sure the part between .log and the final digit doesn't contain any / so it matches on the file name only.



            With -regex, you can go further in specifying the patterns, especially if you enable extended regexps, using -E with some BSD's find or -regextype posix-extended with GNU find.



            find . -regextype posix-extended -regex '.*.log([.-][0-9]+)+' # GNU
            find -E . -regex '.*.log([.-][0-9]+)+' # BSD


            Here matching on .log followed by one or more .<number> or -<number>.



            Without -regextype posix-extended GNU find's regexps are emacs regexps, some sort of hybrid between standard basic regexps and standard extended regexps (supports +, but grouping is with (...) instead of (...)).



            Without -E BSD find regexps are standard basic regexps.






            share|improve this answer












            -regex (a GNU extension also recognised by some other find implementations nowadays but with major differences) is like -path except that it uses regexps instead of wildcards. It matches on the whole file path, not just its name.



            So .*.log.*[0-9] (no need for ^ or $ by the way, they're implicit with find's -regex) would match on ./dir/foo.log-3 but also ./foo.logic/file.bz2, where the .* captured ic/file.bz.



            -name matches on the file name only, uses wildcards but doesn't have a regexp counterpart. Here, for files whose name contain .log and end in a digit, you don't need regexps anyway, -name '*.foo*[0-9]'.



            You can do the same with regexps though with -regex '.*.log[^/]*[0-9]', that is making sure the part between .log and the final digit doesn't contain any / so it matches on the file name only.



            With -regex, you can go further in specifying the patterns, especially if you enable extended regexps, using -E with some BSD's find or -regextype posix-extended with GNU find.



            find . -regextype posix-extended -regex '.*.log([.-][0-9]+)+' # GNU
            find -E . -regex '.*.log([.-][0-9]+)+' # BSD


            Here matching on .log followed by one or more .<number> or -<number>.



            Without -regextype posix-extended GNU find's regexps are emacs regexps, some sort of hybrid between standard basic regexps and standard extended regexps (supports +, but grouping is with (...) instead of (...)).



            Without -E BSD find regexps are standard basic regexps.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Aug 29 at 22:06









            Stéphane Chazelas

            286k53527866




            286k53527866






















                up vote
                0
                down vote













                Try,



                find . -type f -regex ".*.log..*[0-9]$"
                ./server.log.2018-01-23-12
                ./server.log.2018-07-07-06
                ./log-cleaner.log.2
                ./log-cleaner.log.10
                ./server.log.232.434
                ./server.log.2018-01-23-11
                ./server.log.2017-10-31-03
                ./controller.log.2018-01-03-01
                ./server.log.2018-04-06-17
                ./log-cleaner.log.1
                ./controller.log.2018-01-03-03
                ./server.log.2018-04-06-18
                ./controller.log.2018-01-03-02
                ./server.log.2018-07-07-05
                ./server.log.2017-10-31-04


                • we need to escape the .





                share|improve this answer




















                • this syntax not works
                  – yael
                  Aug 29 at 10:31










                • @yeal can you share the error
                  – msp9011
                  Aug 29 at 10:33










                • it si just print only the file - gc.log.0 , but all other are not printed
                  – yael
                  Aug 29 at 10:34










                • yes I already did it
                  – yael
                  Aug 29 at 10:38










                • what you mean ?
                  – yael
                  Aug 29 at 10:48














                up vote
                0
                down vote













                Try,



                find . -type f -regex ".*.log..*[0-9]$"
                ./server.log.2018-01-23-12
                ./server.log.2018-07-07-06
                ./log-cleaner.log.2
                ./log-cleaner.log.10
                ./server.log.232.434
                ./server.log.2018-01-23-11
                ./server.log.2017-10-31-03
                ./controller.log.2018-01-03-01
                ./server.log.2018-04-06-17
                ./log-cleaner.log.1
                ./controller.log.2018-01-03-03
                ./server.log.2018-04-06-18
                ./controller.log.2018-01-03-02
                ./server.log.2018-07-07-05
                ./server.log.2017-10-31-04


                • we need to escape the .





                share|improve this answer




















                • this syntax not works
                  – yael
                  Aug 29 at 10:31










                • @yeal can you share the error
                  – msp9011
                  Aug 29 at 10:33










                • it si just print only the file - gc.log.0 , but all other are not printed
                  – yael
                  Aug 29 at 10:34










                • yes I already did it
                  – yael
                  Aug 29 at 10:38










                • what you mean ?
                  – yael
                  Aug 29 at 10:48












                up vote
                0
                down vote










                up vote
                0
                down vote









                Try,



                find . -type f -regex ".*.log..*[0-9]$"
                ./server.log.2018-01-23-12
                ./server.log.2018-07-07-06
                ./log-cleaner.log.2
                ./log-cleaner.log.10
                ./server.log.232.434
                ./server.log.2018-01-23-11
                ./server.log.2017-10-31-03
                ./controller.log.2018-01-03-01
                ./server.log.2018-04-06-17
                ./log-cleaner.log.1
                ./controller.log.2018-01-03-03
                ./server.log.2018-04-06-18
                ./controller.log.2018-01-03-02
                ./server.log.2018-07-07-05
                ./server.log.2017-10-31-04


                • we need to escape the .





                share|improve this answer












                Try,



                find . -type f -regex ".*.log..*[0-9]$"
                ./server.log.2018-01-23-12
                ./server.log.2018-07-07-06
                ./log-cleaner.log.2
                ./log-cleaner.log.10
                ./server.log.232.434
                ./server.log.2018-01-23-11
                ./server.log.2017-10-31-03
                ./controller.log.2018-01-03-01
                ./server.log.2018-04-06-17
                ./log-cleaner.log.1
                ./controller.log.2018-01-03-03
                ./server.log.2018-04-06-18
                ./controller.log.2018-01-03-02
                ./server.log.2018-07-07-05
                ./server.log.2017-10-31-04


                • we need to escape the .






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 29 at 10:15









                msp9011

                3,46643862




                3,46643862











                • this syntax not works
                  – yael
                  Aug 29 at 10:31










                • @yeal can you share the error
                  – msp9011
                  Aug 29 at 10:33










                • it si just print only the file - gc.log.0 , but all other are not printed
                  – yael
                  Aug 29 at 10:34










                • yes I already did it
                  – yael
                  Aug 29 at 10:38










                • what you mean ?
                  – yael
                  Aug 29 at 10:48
















                • this syntax not works
                  – yael
                  Aug 29 at 10:31










                • @yeal can you share the error
                  – msp9011
                  Aug 29 at 10:33










                • it si just print only the file - gc.log.0 , but all other are not printed
                  – yael
                  Aug 29 at 10:34










                • yes I already did it
                  – yael
                  Aug 29 at 10:38










                • what you mean ?
                  – yael
                  Aug 29 at 10:48















                this syntax not works
                – yael
                Aug 29 at 10:31




                this syntax not works
                – yael
                Aug 29 at 10:31












                @yeal can you share the error
                – msp9011
                Aug 29 at 10:33




                @yeal can you share the error
                – msp9011
                Aug 29 at 10:33












                it si just print only the file - gc.log.0 , but all other are not printed
                – yael
                Aug 29 at 10:34




                it si just print only the file - gc.log.0 , but all other are not printed
                – yael
                Aug 29 at 10:34












                yes I already did it
                – yael
                Aug 29 at 10:38




                yes I already did it
                – yael
                Aug 29 at 10:38












                what you mean ?
                – yael
                Aug 29 at 10:48




                what you mean ?
                – yael
                Aug 29 at 10:48










                up vote
                0
                down vote













                If after "log" there's only digits, ., and -, the following might work as well



                find . -type f -regex ".*[.]log[-.0-9]*$" 





                share|improve this answer
























                  up vote
                  0
                  down vote













                  If after "log" there's only digits, ., and -, the following might work as well



                  find . -type f -regex ".*[.]log[-.0-9]*$" 





                  share|improve this answer






















                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    If after "log" there's only digits, ., and -, the following might work as well



                    find . -type f -regex ".*[.]log[-.0-9]*$" 





                    share|improve this answer












                    If after "log" there's only digits, ., and -, the following might work as well



                    find . -type f -regex ".*[.]log[-.0-9]*$" 






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Aug 29 at 20:34









                    RudiC

                    1,2498




                    1,2498




















                        up vote
                        0
                        down vote













                        You could search for your files using the following way without recourse to non-GNU find:



                        find . -type f 
                        ( -name '?*.log.[0-9]' -o
                        (
                        -name '?*.log.[0-9]*[0-9]'
                        ! -name '?*.log.?*[!0-9.-]*?'
                        ! -name '?*.log.?*[.-][.-]*?'
                        )
                        )
                        -print;


                        What this does is do a multi-layered filtering of the filenames caught by it and progressively shrinks the catch and zeroes in on the required. To be precise:



                        • Right away select any file whose basename, i.e., w/o it's path ends in a .log.single_digit

                        • OTW, select those that end in .log. NUM anything NUM This will set the trend for the filenames to be caught in the net.

                        • Out of the above catch, reject those which happen to have a non number, non dash, or non dot in the anything portion of the filename. Note the trend of beginning and ending with a digit must be honored.

                        • Now our catch has all those files in which anything portion comprises only digit(s), dot(s), and dash(s). The last constraint is that the dot or dash must not have each as their immediate neighbors to both their left and right.

                        • P.S. Note that -name option looks at the basename portion of the filename only, AND


                        • -name portion operates on the wildcard basis and hence they are implicitly anchored, meaning the name matched is full.





                        share|improve this answer
























                          up vote
                          0
                          down vote













                          You could search for your files using the following way without recourse to non-GNU find:



                          find . -type f 
                          ( -name '?*.log.[0-9]' -o
                          (
                          -name '?*.log.[0-9]*[0-9]'
                          ! -name '?*.log.?*[!0-9.-]*?'
                          ! -name '?*.log.?*[.-][.-]*?'
                          )
                          )
                          -print;


                          What this does is do a multi-layered filtering of the filenames caught by it and progressively shrinks the catch and zeroes in on the required. To be precise:



                          • Right away select any file whose basename, i.e., w/o it's path ends in a .log.single_digit

                          • OTW, select those that end in .log. NUM anything NUM This will set the trend for the filenames to be caught in the net.

                          • Out of the above catch, reject those which happen to have a non number, non dash, or non dot in the anything portion of the filename. Note the trend of beginning and ending with a digit must be honored.

                          • Now our catch has all those files in which anything portion comprises only digit(s), dot(s), and dash(s). The last constraint is that the dot or dash must not have each as their immediate neighbors to both their left and right.

                          • P.S. Note that -name option looks at the basename portion of the filename only, AND


                          • -name portion operates on the wildcard basis and hence they are implicitly anchored, meaning the name matched is full.





                          share|improve this answer






















                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            You could search for your files using the following way without recourse to non-GNU find:



                            find . -type f 
                            ( -name '?*.log.[0-9]' -o
                            (
                            -name '?*.log.[0-9]*[0-9]'
                            ! -name '?*.log.?*[!0-9.-]*?'
                            ! -name '?*.log.?*[.-][.-]*?'
                            )
                            )
                            -print;


                            What this does is do a multi-layered filtering of the filenames caught by it and progressively shrinks the catch and zeroes in on the required. To be precise:



                            • Right away select any file whose basename, i.e., w/o it's path ends in a .log.single_digit

                            • OTW, select those that end in .log. NUM anything NUM This will set the trend for the filenames to be caught in the net.

                            • Out of the above catch, reject those which happen to have a non number, non dash, or non dot in the anything portion of the filename. Note the trend of beginning and ending with a digit must be honored.

                            • Now our catch has all those files in which anything portion comprises only digit(s), dot(s), and dash(s). The last constraint is that the dot or dash must not have each as their immediate neighbors to both their left and right.

                            • P.S. Note that -name option looks at the basename portion of the filename only, AND


                            • -name portion operates on the wildcard basis and hence they are implicitly anchored, meaning the name matched is full.





                            share|improve this answer












                            You could search for your files using the following way without recourse to non-GNU find:



                            find . -type f 
                            ( -name '?*.log.[0-9]' -o
                            (
                            -name '?*.log.[0-9]*[0-9]'
                            ! -name '?*.log.?*[!0-9.-]*?'
                            ! -name '?*.log.?*[.-][.-]*?'
                            )
                            )
                            -print;


                            What this does is do a multi-layered filtering of the filenames caught by it and progressively shrinks the catch and zeroes in on the required. To be precise:



                            • Right away select any file whose basename, i.e., w/o it's path ends in a .log.single_digit

                            • OTW, select those that end in .log. NUM anything NUM This will set the trend for the filenames to be caught in the net.

                            • Out of the above catch, reject those which happen to have a non number, non dash, or non dot in the anything portion of the filename. Note the trend of beginning and ending with a digit must be honored.

                            • Now our catch has all those files in which anything portion comprises only digit(s), dot(s), and dash(s). The last constraint is that the dot or dash must not have each as their immediate neighbors to both their left and right.

                            • P.S. Note that -name option looks at the basename portion of the filename only, AND


                            • -name portion operates on the wildcard basis and hence they are implicitly anchored, meaning the name matched is full.






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Sep 2 at 5:43









                            Rakesh Sharma

                            60513




                            60513



























                                 

                                draft saved


                                draft discarded















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f465459%2fcapture-log-files-that-ended-with-any-number%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