How do I find a file whose name has five digits, in a row, somewhere in the file name?












0















Normally, I would ask a professor or classmate this, but as it's a Saturday and everyone is gone. I have to find a file in a directory that has five digits in a row somewhere in the file name. They don't have to be ascending or descending digits.










share|improve this question




















  • 1





    Related: unix.stackexchange.com/questions/134684/…

    – Jeff Schaller
    Jan 19 at 16:06











  • Also: unix.stackexchange.com/questions/234201/…

    – Jeff Schaller
    Jan 19 at 16:06











  • This command line should do it. find . -name "*[0-9][0-9][0-9][0-9][0-9]*". It can probably be simplified. If there must be exactly 5 digits, that expression will be more complicated.

    – sudodus
    Jan 19 at 16:08













  • See also unix.stackexchange.com/q/414226/117549

    – Jeff Schaller
    Jan 19 at 16:18











  • If you want to search subdirectories as well: find -E directory/ -regex '.*[0-9]{5,}.*'

    – Nick Garvey
    Jan 19 at 17:46


















0















Normally, I would ask a professor or classmate this, but as it's a Saturday and everyone is gone. I have to find a file in a directory that has five digits in a row somewhere in the file name. They don't have to be ascending or descending digits.










share|improve this question




















  • 1





    Related: unix.stackexchange.com/questions/134684/…

    – Jeff Schaller
    Jan 19 at 16:06











  • Also: unix.stackexchange.com/questions/234201/…

    – Jeff Schaller
    Jan 19 at 16:06











  • This command line should do it. find . -name "*[0-9][0-9][0-9][0-9][0-9]*". It can probably be simplified. If there must be exactly 5 digits, that expression will be more complicated.

    – sudodus
    Jan 19 at 16:08













  • See also unix.stackexchange.com/q/414226/117549

    – Jeff Schaller
    Jan 19 at 16:18











  • If you want to search subdirectories as well: find -E directory/ -regex '.*[0-9]{5,}.*'

    – Nick Garvey
    Jan 19 at 17:46
















0












0








0








Normally, I would ask a professor or classmate this, but as it's a Saturday and everyone is gone. I have to find a file in a directory that has five digits in a row somewhere in the file name. They don't have to be ascending or descending digits.










share|improve this question
















Normally, I would ask a professor or classmate this, but as it's a Saturday and everyone is gone. I have to find a file in a directory that has five digits in a row somewhere in the file name. They don't have to be ascending or descending digits.







linux command-line filenames






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 19 at 16:03









Jeff Schaller

42.9k1159136




42.9k1159136










asked Jan 19 at 15:58









Irish JetIrish Jet

41




41








  • 1





    Related: unix.stackexchange.com/questions/134684/…

    – Jeff Schaller
    Jan 19 at 16:06











  • Also: unix.stackexchange.com/questions/234201/…

    – Jeff Schaller
    Jan 19 at 16:06











  • This command line should do it. find . -name "*[0-9][0-9][0-9][0-9][0-9]*". It can probably be simplified. If there must be exactly 5 digits, that expression will be more complicated.

    – sudodus
    Jan 19 at 16:08













  • See also unix.stackexchange.com/q/414226/117549

    – Jeff Schaller
    Jan 19 at 16:18











  • If you want to search subdirectories as well: find -E directory/ -regex '.*[0-9]{5,}.*'

    – Nick Garvey
    Jan 19 at 17:46
















  • 1





    Related: unix.stackexchange.com/questions/134684/…

    – Jeff Schaller
    Jan 19 at 16:06











  • Also: unix.stackexchange.com/questions/234201/…

    – Jeff Schaller
    Jan 19 at 16:06











  • This command line should do it. find . -name "*[0-9][0-9][0-9][0-9][0-9]*". It can probably be simplified. If there must be exactly 5 digits, that expression will be more complicated.

    – sudodus
    Jan 19 at 16:08













  • See also unix.stackexchange.com/q/414226/117549

    – Jeff Schaller
    Jan 19 at 16:18











  • If you want to search subdirectories as well: find -E directory/ -regex '.*[0-9]{5,}.*'

    – Nick Garvey
    Jan 19 at 17:46










1




1





Related: unix.stackexchange.com/questions/134684/…

– Jeff Schaller
Jan 19 at 16:06





Related: unix.stackexchange.com/questions/134684/…

– Jeff Schaller
Jan 19 at 16:06













Also: unix.stackexchange.com/questions/234201/…

– Jeff Schaller
Jan 19 at 16:06





Also: unix.stackexchange.com/questions/234201/…

– Jeff Schaller
Jan 19 at 16:06













This command line should do it. find . -name "*[0-9][0-9][0-9][0-9][0-9]*". It can probably be simplified. If there must be exactly 5 digits, that expression will be more complicated.

– sudodus
Jan 19 at 16:08







This command line should do it. find . -name "*[0-9][0-9][0-9][0-9][0-9]*". It can probably be simplified. If there must be exactly 5 digits, that expression will be more complicated.

– sudodus
Jan 19 at 16:08















See also unix.stackexchange.com/q/414226/117549

– Jeff Schaller
Jan 19 at 16:18





See also unix.stackexchange.com/q/414226/117549

– Jeff Schaller
Jan 19 at 16:18













If you want to search subdirectories as well: find -E directory/ -regex '.*[0-9]{5,}.*'

– Nick Garvey
Jan 19 at 17:46







If you want to search subdirectories as well: find -E directory/ -regex '.*[0-9]{5,}.*'

– Nick Garvey
Jan 19 at 17:46












2 Answers
2






active

oldest

votes


















4














Wildcards (or globs) can accomplish this, with a numeric range:



ls -d /path/to/directory/*[0-9][0-9][0-9][0-9][0-9]*


This tells the shell to look in /path/to/directory for filenames that start with:





  • * -- anything (or nothing)


  • [0-9] -- a digit

  • (four more digits)


  • * -- and ending in anything (or nothing)


That list of filenames is then passed to ls to list them.



More expansively, bash also allows character classes as wildcards, so if you have numbers in your language that aren't covered by [0-9], you could use:



ls -d *[[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]*





share|improve this answer





















  • 1





    Maybe add -d to avoid listing the contents of directories that match, i.e. ls -d /path/to/directory/*[0-9][0-9][0-9][0-9][0-9]*

    – bitinerant
    Jan 19 at 17:06





















-1














I have achieved by below method and i worked fine



find . -maxdepth 1  -type f| sed "s/.///g"| awk -F "." '{print $1}'|sed '/^$/d'| awk '/[0-9]/{print $0}'| awk '{print $1,gsub("[0-9]",$1)}'| awk '$2 == 5 {print $1}'





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


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f495471%2fhow-do-i-find-a-file-whose-name-has-five-digits-in-a-row-somewhere-in-the-file%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









    4














    Wildcards (or globs) can accomplish this, with a numeric range:



    ls -d /path/to/directory/*[0-9][0-9][0-9][0-9][0-9]*


    This tells the shell to look in /path/to/directory for filenames that start with:





    • * -- anything (or nothing)


    • [0-9] -- a digit

    • (four more digits)


    • * -- and ending in anything (or nothing)


    That list of filenames is then passed to ls to list them.



    More expansively, bash also allows character classes as wildcards, so if you have numbers in your language that aren't covered by [0-9], you could use:



    ls -d *[[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]*





    share|improve this answer





















    • 1





      Maybe add -d to avoid listing the contents of directories that match, i.e. ls -d /path/to/directory/*[0-9][0-9][0-9][0-9][0-9]*

      – bitinerant
      Jan 19 at 17:06


















    4














    Wildcards (or globs) can accomplish this, with a numeric range:



    ls -d /path/to/directory/*[0-9][0-9][0-9][0-9][0-9]*


    This tells the shell to look in /path/to/directory for filenames that start with:





    • * -- anything (or nothing)


    • [0-9] -- a digit

    • (four more digits)


    • * -- and ending in anything (or nothing)


    That list of filenames is then passed to ls to list them.



    More expansively, bash also allows character classes as wildcards, so if you have numbers in your language that aren't covered by [0-9], you could use:



    ls -d *[[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]*





    share|improve this answer





















    • 1





      Maybe add -d to avoid listing the contents of directories that match, i.e. ls -d /path/to/directory/*[0-9][0-9][0-9][0-9][0-9]*

      – bitinerant
      Jan 19 at 17:06
















    4












    4








    4







    Wildcards (or globs) can accomplish this, with a numeric range:



    ls -d /path/to/directory/*[0-9][0-9][0-9][0-9][0-9]*


    This tells the shell to look in /path/to/directory for filenames that start with:





    • * -- anything (or nothing)


    • [0-9] -- a digit

    • (four more digits)


    • * -- and ending in anything (or nothing)


    That list of filenames is then passed to ls to list them.



    More expansively, bash also allows character classes as wildcards, so if you have numbers in your language that aren't covered by [0-9], you could use:



    ls -d *[[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]*





    share|improve this answer















    Wildcards (or globs) can accomplish this, with a numeric range:



    ls -d /path/to/directory/*[0-9][0-9][0-9][0-9][0-9]*


    This tells the shell to look in /path/to/directory for filenames that start with:





    • * -- anything (or nothing)


    • [0-9] -- a digit

    • (four more digits)


    • * -- and ending in anything (or nothing)


    That list of filenames is then passed to ls to list them.



    More expansively, bash also allows character classes as wildcards, so if you have numbers in your language that aren't covered by [0-9], you could use:



    ls -d *[[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]*






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 19 at 17:10

























    answered Jan 19 at 16:12









    Jeff SchallerJeff Schaller

    42.9k1159136




    42.9k1159136








    • 1





      Maybe add -d to avoid listing the contents of directories that match, i.e. ls -d /path/to/directory/*[0-9][0-9][0-9][0-9][0-9]*

      – bitinerant
      Jan 19 at 17:06
















    • 1





      Maybe add -d to avoid listing the contents of directories that match, i.e. ls -d /path/to/directory/*[0-9][0-9][0-9][0-9][0-9]*

      – bitinerant
      Jan 19 at 17:06










    1




    1





    Maybe add -d to avoid listing the contents of directories that match, i.e. ls -d /path/to/directory/*[0-9][0-9][0-9][0-9][0-9]*

    – bitinerant
    Jan 19 at 17:06







    Maybe add -d to avoid listing the contents of directories that match, i.e. ls -d /path/to/directory/*[0-9][0-9][0-9][0-9][0-9]*

    – bitinerant
    Jan 19 at 17:06















    -1














    I have achieved by below method and i worked fine



    find . -maxdepth 1  -type f| sed "s/.///g"| awk -F "." '{print $1}'|sed '/^$/d'| awk '/[0-9]/{print $0}'| awk '{print $1,gsub("[0-9]",$1)}'| awk '$2 == 5 {print $1}'





    share|improve this answer




























      -1














      I have achieved by below method and i worked fine



      find . -maxdepth 1  -type f| sed "s/.///g"| awk -F "." '{print $1}'|sed '/^$/d'| awk '/[0-9]/{print $0}'| awk '{print $1,gsub("[0-9]",$1)}'| awk '$2 == 5 {print $1}'





      share|improve this answer


























        -1












        -1








        -1







        I have achieved by below method and i worked fine



        find . -maxdepth 1  -type f| sed "s/.///g"| awk -F "." '{print $1}'|sed '/^$/d'| awk '/[0-9]/{print $0}'| awk '{print $1,gsub("[0-9]",$1)}'| awk '$2 == 5 {print $1}'





        share|improve this answer













        I have achieved by below method and i worked fine



        find . -maxdepth 1  -type f| sed "s/.///g"| awk -F "." '{print $1}'|sed '/^$/d'| awk '/[0-9]/{print $0}'| awk '{print $1,gsub("[0-9]",$1)}'| awk '$2 == 5 {print $1}'






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 20 at 8:58









        Praveen Kumar BSPraveen Kumar BS

        1,5041310




        1,5041310






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f495471%2fhow-do-i-find-a-file-whose-name-has-five-digits-in-a-row-somewhere-in-the-file%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

            MongoDB - Not Authorized To Execute Command

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

            Npm cannot find a required file even through it is in the searched directory