How do I count the files in the current directory whose names are at least 5 characters long?

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











up vote
0
down vote

favorite












I am trying to use ls and grep. However, I cannot figure out a way to count how many files in the current directory have a name long at least 5 characters.



How can I achieve this?







share|improve this question






















  • should files in subfolders be considered?
    – RomanPerekhrest
    Oct 29 '17 at 5:46










  • No just the current directory, not recursive
    – 2310
    Oct 29 '17 at 5:47






  • 1




    What have you tried so far? How would you grep for lines with at least five characters?
    – Mikel
    Oct 29 '17 at 5:47










  • and directory names should be skipped, only files?
    – RomanPerekhrest
    Oct 29 '17 at 5:48







  • 2




    @2310, note, this filename a.txt has also 5 charatcers, including extension. You see how many questions were asked? Advice: always describe and elaborate your questions with details!
    – RomanPerekhrest
    Oct 29 '17 at 5:50















up vote
0
down vote

favorite












I am trying to use ls and grep. However, I cannot figure out a way to count how many files in the current directory have a name long at least 5 characters.



How can I achieve this?







share|improve this question






















  • should files in subfolders be considered?
    – RomanPerekhrest
    Oct 29 '17 at 5:46










  • No just the current directory, not recursive
    – 2310
    Oct 29 '17 at 5:47






  • 1




    What have you tried so far? How would you grep for lines with at least five characters?
    – Mikel
    Oct 29 '17 at 5:47










  • and directory names should be skipped, only files?
    – RomanPerekhrest
    Oct 29 '17 at 5:48







  • 2




    @2310, note, this filename a.txt has also 5 charatcers, including extension. You see how many questions were asked? Advice: always describe and elaborate your questions with details!
    – RomanPerekhrest
    Oct 29 '17 at 5:50













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying to use ls and grep. However, I cannot figure out a way to count how many files in the current directory have a name long at least 5 characters.



How can I achieve this?







share|improve this question














I am trying to use ls and grep. However, I cannot figure out a way to count how many files in the current directory have a name long at least 5 characters.



How can I achieve this?









share|improve this question













share|improve this question




share|improve this question








edited Oct 29 '17 at 6:27









Satō Katsura

10.7k11533




10.7k11533










asked Oct 29 '17 at 5:45









2310

6




6











  • should files in subfolders be considered?
    – RomanPerekhrest
    Oct 29 '17 at 5:46










  • No just the current directory, not recursive
    – 2310
    Oct 29 '17 at 5:47






  • 1




    What have you tried so far? How would you grep for lines with at least five characters?
    – Mikel
    Oct 29 '17 at 5:47










  • and directory names should be skipped, only files?
    – RomanPerekhrest
    Oct 29 '17 at 5:48







  • 2




    @2310, note, this filename a.txt has also 5 charatcers, including extension. You see how many questions were asked? Advice: always describe and elaborate your questions with details!
    – RomanPerekhrest
    Oct 29 '17 at 5:50

















  • should files in subfolders be considered?
    – RomanPerekhrest
    Oct 29 '17 at 5:46










  • No just the current directory, not recursive
    – 2310
    Oct 29 '17 at 5:47






  • 1




    What have you tried so far? How would you grep for lines with at least five characters?
    – Mikel
    Oct 29 '17 at 5:47










  • and directory names should be skipped, only files?
    – RomanPerekhrest
    Oct 29 '17 at 5:48







  • 2




    @2310, note, this filename a.txt has also 5 charatcers, including extension. You see how many questions were asked? Advice: always describe and elaborate your questions with details!
    – RomanPerekhrest
    Oct 29 '17 at 5:50
















should files in subfolders be considered?
– RomanPerekhrest
Oct 29 '17 at 5:46




should files in subfolders be considered?
– RomanPerekhrest
Oct 29 '17 at 5:46












No just the current directory, not recursive
– 2310
Oct 29 '17 at 5:47




No just the current directory, not recursive
– 2310
Oct 29 '17 at 5:47




1




1




What have you tried so far? How would you grep for lines with at least five characters?
– Mikel
Oct 29 '17 at 5:47




What have you tried so far? How would you grep for lines with at least five characters?
– Mikel
Oct 29 '17 at 5:47












and directory names should be skipped, only files?
– RomanPerekhrest
Oct 29 '17 at 5:48





and directory names should be skipped, only files?
– RomanPerekhrest
Oct 29 '17 at 5:48





2




2




@2310, note, this filename a.txt has also 5 charatcers, including extension. You see how many questions were asked? Advice: always describe and elaborate your questions with details!
– RomanPerekhrest
Oct 29 '17 at 5:50





@2310, note, this filename a.txt has also 5 charatcers, including extension. You see how many questions were asked? Advice: always describe and elaborate your questions with details!
– RomanPerekhrest
Oct 29 '17 at 5:50











2 Answers
2






active

oldest

votes

















up vote
2
down vote













Simple find + wc commands solution:



find . -maxdepth 1 -type f -name "?????*" | wc -l





share|improve this answer



























    up vote
    0
    down vote













    If this is homework, the assignment may be looking for something like:



    ls | grep ..... | wc -l


    Though I would do:



    set -- ?????*
    echo $#


    or



    files=(?????*)
    echo $#files[@]


    Here the important work is done by the shell glob . which says to match one character of a filename; by including 5 of them followed by a * (any number of characters), we generate the list of files with at least 5 characters in them.



    The counting is then done by the $# shell parameter in the set solution, or by counting the elements in the array.






    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%2f401158%2fhow-do-i-count-the-files-in-the-current-directory-whose-names-are-at-least-5-cha%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      2
      down vote













      Simple find + wc commands solution:



      find . -maxdepth 1 -type f -name "?????*" | wc -l





      share|improve this answer
























        up vote
        2
        down vote













        Simple find + wc commands solution:



        find . -maxdepth 1 -type f -name "?????*" | wc -l





        share|improve this answer






















          up vote
          2
          down vote










          up vote
          2
          down vote









          Simple find + wc commands solution:



          find . -maxdepth 1 -type f -name "?????*" | wc -l





          share|improve this answer












          Simple find + wc commands solution:



          find . -maxdepth 1 -type f -name "?????*" | wc -l






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Oct 29 '17 at 5:54









          RomanPerekhrest

          22.5k12145




          22.5k12145






















              up vote
              0
              down vote













              If this is homework, the assignment may be looking for something like:



              ls | grep ..... | wc -l


              Though I would do:



              set -- ?????*
              echo $#


              or



              files=(?????*)
              echo $#files[@]


              Here the important work is done by the shell glob . which says to match one character of a filename; by including 5 of them followed by a * (any number of characters), we generate the list of files with at least 5 characters in them.



              The counting is then done by the $# shell parameter in the set solution, or by counting the elements in the array.






              share|improve this answer
























                up vote
                0
                down vote













                If this is homework, the assignment may be looking for something like:



                ls | grep ..... | wc -l


                Though I would do:



                set -- ?????*
                echo $#


                or



                files=(?????*)
                echo $#files[@]


                Here the important work is done by the shell glob . which says to match one character of a filename; by including 5 of them followed by a * (any number of characters), we generate the list of files with at least 5 characters in them.



                The counting is then done by the $# shell parameter in the set solution, or by counting the elements in the array.






                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  If this is homework, the assignment may be looking for something like:



                  ls | grep ..... | wc -l


                  Though I would do:



                  set -- ?????*
                  echo $#


                  or



                  files=(?????*)
                  echo $#files[@]


                  Here the important work is done by the shell glob . which says to match one character of a filename; by including 5 of them followed by a * (any number of characters), we generate the list of files with at least 5 characters in them.



                  The counting is then done by the $# shell parameter in the set solution, or by counting the elements in the array.






                  share|improve this answer












                  If this is homework, the assignment may be looking for something like:



                  ls | grep ..... | wc -l


                  Though I would do:



                  set -- ?????*
                  echo $#


                  or



                  files=(?????*)
                  echo $#files[@]


                  Here the important work is done by the shell glob . which says to match one character of a filename; by including 5 of them followed by a * (any number of characters), we generate the list of files with at least 5 characters in them.



                  The counting is then done by the $# shell parameter in the set solution, or by counting the elements in the array.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 29 '17 at 13:10









                  Jeff Schaller

                  32.1k849109




                  32.1k849109



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f401158%2fhow-do-i-count-the-files-in-the-current-directory-whose-names-are-at-least-5-cha%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?

                      Displaying single band from multi-band raster using QGIS

                      How many registers does an x86_64 CPU actually have?