How do you list number of lines of every file in a directory in human readable format.

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











up vote
26
down vote

favorite
7












I have a list of directories and subdirectories that contain large csv files. There are about 500 million lines in these files, each is a record. I would like to know



  1. How many lines are in each file.

  2. How many lines are in directory.

  3. How many lines in total

Most importantly, I need this in 'human readable format' eg. 12,345,678 rather than 12345678



It would be nice to learn how to do this in 3 ways. Plain vanilla bash tools, awk etc., and perl (or python).










share|improve this question

























    up vote
    26
    down vote

    favorite
    7












    I have a list of directories and subdirectories that contain large csv files. There are about 500 million lines in these files, each is a record. I would like to know



    1. How many lines are in each file.

    2. How many lines are in directory.

    3. How many lines in total

    Most importantly, I need this in 'human readable format' eg. 12,345,678 rather than 12345678



    It would be nice to learn how to do this in 3 ways. Plain vanilla bash tools, awk etc., and perl (or python).










    share|improve this question























      up vote
      26
      down vote

      favorite
      7









      up vote
      26
      down vote

      favorite
      7






      7





      I have a list of directories and subdirectories that contain large csv files. There are about 500 million lines in these files, each is a record. I would like to know



      1. How many lines are in each file.

      2. How many lines are in directory.

      3. How many lines in total

      Most importantly, I need this in 'human readable format' eg. 12,345,678 rather than 12345678



      It would be nice to learn how to do this in 3 ways. Plain vanilla bash tools, awk etc., and perl (or python).










      share|improve this question













      I have a list of directories and subdirectories that contain large csv files. There are about 500 million lines in these files, each is a record. I would like to know



      1. How many lines are in each file.

      2. How many lines are in directory.

      3. How many lines in total

      Most importantly, I need this in 'human readable format' eg. 12,345,678 rather than 12345678



      It would be nice to learn how to do this in 3 ways. Plain vanilla bash tools, awk etc., and perl (or python).







      bash awk python perl






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 7 '16 at 19:16









      Hexatonic

      255148




      255148




















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          38
          down vote



          accepted











          How many lines are in each file.




          Use wc, originally for word count, I believe, but it can do lines, words, characters, bytes, and the longest line length. The -l option tells it to count lines.



          wc -l <filename>


          This will output the number of lines in :



          $ wc -l /dir/file.txt
          32724 /dir/file.txt


          You can also pipe data to wc as well:



          $ cat /dir/file.txt | wc -l
          32724
          $ curl google.com --silent | wc -l
          63



          How many lines are in directory.




          Try:



          find . -name '*.pl' | xargs wc -l


          another one-liner:



          ( find ./ -name '*.pl' -print0 | xargs -0 cat ) | wc -l


          BTW, wc command counts new lines codes, not lines. When last line in the file does not end with new line code, this will not counted.



          You may use grep -c ^ , full example:



          #this example prints line count for all found files
          total=0
          find /path -type f -name "*.php" | while read FILE; do
          #you see use grep instead wc ! for properly counting
          count=$(grep -c ^ < "$FILE")
          echo "$FILE has $count lines"
          let total=total+count #in bash, you can convert this for another shell
          done
          echo TOTAL LINES COUNTED: $total



          How many lines in total




          Not sure that I understood you request correctly. e.g. this will output results in the following format, showing the number of lines for each file:



          # wc -l `find /path/to/directory/ -type f`
          103 /dir/a.php
          378 /dir/b/c.xml
          132 /dir/d/e.xml
          613 total


          Alternatively, to output just the total number of new line characters without the file by file counts to following command can prove useful:



          # find /path/to/directory/ -type f -exec wc -l ; | awk 'total += $1 ENDprint total'
          613



          Most importantly, I need this in 'human readable format' eg.
          12,345,678 rather than 12345678




          Bash has a printf function built in:



          printf "%0.2fn" $T


          As always, there are many different methods that could be used to achieve the same results mentioned here.






          share|improve this answer




















          • By the way, how do I use printf in your examples? I tried to pipe to it from wc -l, but it didn't work.
            – Hexatonic
            Feb 8 '16 at 2:12










          • try > find . -name '*.pl' | xargs wc -l | awk 'printf ("%0.2f ", $1) print $2' change the output of 'printf' for your needs
            – malyy
            Feb 8 '16 at 15:34










          • This doesn't add commas to the number to make it more human readable though. It just adds a zeros to the end.
            – Hexatonic
            Feb 8 '16 at 16:05










          • echo 1000000000000 | xargs printf "%'dn" 1,000,000,000,000
            – Hexatonic
            Feb 8 '16 at 16:07






          • 1




            @Hexatonic printf doesn't read its arguments from stdin, but rather from the command line (compare piping to echo vs piping to cat; cat reads from stdin, echo doesn't). Instead, use printf "$(find ... | xargs ...)" to supply the output as arguments to printf.
            – BallpointBen
            Aug 21 at 22:02

















          up vote
          5
          down vote













          In many cases combining the wc command and the wildcard * may be enough.

          If all your files are in a single directory you can call:



          wc -l src/*


          You can also list several files and directories:



          wc -l file.txt readme src/* include/*


          This command will show a list of the files and their number of lines.

          The last line will be the sum of the lines from all files.




          To count all files in a directory recursively:



          First, enable globstar by adding shopt -s globstar to your .bash_profile. Support for globstar requires Bash ≥ 4.x which can be installed with brew install bash if needed. You can check your version with bash --version.



          Then run:



          wc -l **/*


          Note that this output will be incorrect if globstar is not enabled.






          share|improve this answer






















          • And for counting files in the currrent directory recursively: wc -l **/*
            – Taylor Edmiston
            Mar 31 at 18:35










          • @TaylorEdmiston For me (on Mac) that only counts the files exactly one directory down. It skips the files in the current directory, and for any instance that would be more than one directory deep it warns that it's a directory: "wc: parent_dir/child_dir: read: Is a directory"
            – M. Justin
            Sep 16 at 5:56











          • @Thomio It requires globstar to be enabled. On macOS, I believe it is disabled out of the box. I've just sent an edit to your answer that adds the command and how to enable globstar.
            – Taylor Edmiston
            2 days ago

















          up vote
          1
          down vote













          a bit late to the game, but I got a bunch of argument errors with the above due to the size of the dir. This worked for me:



          for i in $(find . -type f); do wc -l $i; done >> /home/counts.txt






          share|improve this answer



























            up vote
            0
            down vote













            This command will give list of lines code in each directory:



            find . -name '*.*' -type f | xargs wc -l





            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%2f260630%2fhow-do-you-list-number-of-lines-of-every-file-in-a-directory-in-human-readable-f%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
              38
              down vote



              accepted











              How many lines are in each file.




              Use wc, originally for word count, I believe, but it can do lines, words, characters, bytes, and the longest line length. The -l option tells it to count lines.



              wc -l <filename>


              This will output the number of lines in :



              $ wc -l /dir/file.txt
              32724 /dir/file.txt


              You can also pipe data to wc as well:



              $ cat /dir/file.txt | wc -l
              32724
              $ curl google.com --silent | wc -l
              63



              How many lines are in directory.




              Try:



              find . -name '*.pl' | xargs wc -l


              another one-liner:



              ( find ./ -name '*.pl' -print0 | xargs -0 cat ) | wc -l


              BTW, wc command counts new lines codes, not lines. When last line in the file does not end with new line code, this will not counted.



              You may use grep -c ^ , full example:



              #this example prints line count for all found files
              total=0
              find /path -type f -name "*.php" | while read FILE; do
              #you see use grep instead wc ! for properly counting
              count=$(grep -c ^ < "$FILE")
              echo "$FILE has $count lines"
              let total=total+count #in bash, you can convert this for another shell
              done
              echo TOTAL LINES COUNTED: $total



              How many lines in total




              Not sure that I understood you request correctly. e.g. this will output results in the following format, showing the number of lines for each file:



              # wc -l `find /path/to/directory/ -type f`
              103 /dir/a.php
              378 /dir/b/c.xml
              132 /dir/d/e.xml
              613 total


              Alternatively, to output just the total number of new line characters without the file by file counts to following command can prove useful:



              # find /path/to/directory/ -type f -exec wc -l ; | awk 'total += $1 ENDprint total'
              613



              Most importantly, I need this in 'human readable format' eg.
              12,345,678 rather than 12345678




              Bash has a printf function built in:



              printf "%0.2fn" $T


              As always, there are many different methods that could be used to achieve the same results mentioned here.






              share|improve this answer




















              • By the way, how do I use printf in your examples? I tried to pipe to it from wc -l, but it didn't work.
                – Hexatonic
                Feb 8 '16 at 2:12










              • try > find . -name '*.pl' | xargs wc -l | awk 'printf ("%0.2f ", $1) print $2' change the output of 'printf' for your needs
                – malyy
                Feb 8 '16 at 15:34










              • This doesn't add commas to the number to make it more human readable though. It just adds a zeros to the end.
                – Hexatonic
                Feb 8 '16 at 16:05










              • echo 1000000000000 | xargs printf "%'dn" 1,000,000,000,000
                – Hexatonic
                Feb 8 '16 at 16:07






              • 1




                @Hexatonic printf doesn't read its arguments from stdin, but rather from the command line (compare piping to echo vs piping to cat; cat reads from stdin, echo doesn't). Instead, use printf "$(find ... | xargs ...)" to supply the output as arguments to printf.
                – BallpointBen
                Aug 21 at 22:02














              up vote
              38
              down vote



              accepted











              How many lines are in each file.




              Use wc, originally for word count, I believe, but it can do lines, words, characters, bytes, and the longest line length. The -l option tells it to count lines.



              wc -l <filename>


              This will output the number of lines in :



              $ wc -l /dir/file.txt
              32724 /dir/file.txt


              You can also pipe data to wc as well:



              $ cat /dir/file.txt | wc -l
              32724
              $ curl google.com --silent | wc -l
              63



              How many lines are in directory.




              Try:



              find . -name '*.pl' | xargs wc -l


              another one-liner:



              ( find ./ -name '*.pl' -print0 | xargs -0 cat ) | wc -l


              BTW, wc command counts new lines codes, not lines. When last line in the file does not end with new line code, this will not counted.



              You may use grep -c ^ , full example:



              #this example prints line count for all found files
              total=0
              find /path -type f -name "*.php" | while read FILE; do
              #you see use grep instead wc ! for properly counting
              count=$(grep -c ^ < "$FILE")
              echo "$FILE has $count lines"
              let total=total+count #in bash, you can convert this for another shell
              done
              echo TOTAL LINES COUNTED: $total



              How many lines in total




              Not sure that I understood you request correctly. e.g. this will output results in the following format, showing the number of lines for each file:



              # wc -l `find /path/to/directory/ -type f`
              103 /dir/a.php
              378 /dir/b/c.xml
              132 /dir/d/e.xml
              613 total


              Alternatively, to output just the total number of new line characters without the file by file counts to following command can prove useful:



              # find /path/to/directory/ -type f -exec wc -l ; | awk 'total += $1 ENDprint total'
              613



              Most importantly, I need this in 'human readable format' eg.
              12,345,678 rather than 12345678




              Bash has a printf function built in:



              printf "%0.2fn" $T


              As always, there are many different methods that could be used to achieve the same results mentioned here.






              share|improve this answer




















              • By the way, how do I use printf in your examples? I tried to pipe to it from wc -l, but it didn't work.
                – Hexatonic
                Feb 8 '16 at 2:12










              • try > find . -name '*.pl' | xargs wc -l | awk 'printf ("%0.2f ", $1) print $2' change the output of 'printf' for your needs
                – malyy
                Feb 8 '16 at 15:34










              • This doesn't add commas to the number to make it more human readable though. It just adds a zeros to the end.
                – Hexatonic
                Feb 8 '16 at 16:05










              • echo 1000000000000 | xargs printf "%'dn" 1,000,000,000,000
                – Hexatonic
                Feb 8 '16 at 16:07






              • 1




                @Hexatonic printf doesn't read its arguments from stdin, but rather from the command line (compare piping to echo vs piping to cat; cat reads from stdin, echo doesn't). Instead, use printf "$(find ... | xargs ...)" to supply the output as arguments to printf.
                – BallpointBen
                Aug 21 at 22:02












              up vote
              38
              down vote



              accepted







              up vote
              38
              down vote



              accepted







              How many lines are in each file.




              Use wc, originally for word count, I believe, but it can do lines, words, characters, bytes, and the longest line length. The -l option tells it to count lines.



              wc -l <filename>


              This will output the number of lines in :



              $ wc -l /dir/file.txt
              32724 /dir/file.txt


              You can also pipe data to wc as well:



              $ cat /dir/file.txt | wc -l
              32724
              $ curl google.com --silent | wc -l
              63



              How many lines are in directory.




              Try:



              find . -name '*.pl' | xargs wc -l


              another one-liner:



              ( find ./ -name '*.pl' -print0 | xargs -0 cat ) | wc -l


              BTW, wc command counts new lines codes, not lines. When last line in the file does not end with new line code, this will not counted.



              You may use grep -c ^ , full example:



              #this example prints line count for all found files
              total=0
              find /path -type f -name "*.php" | while read FILE; do
              #you see use grep instead wc ! for properly counting
              count=$(grep -c ^ < "$FILE")
              echo "$FILE has $count lines"
              let total=total+count #in bash, you can convert this for another shell
              done
              echo TOTAL LINES COUNTED: $total



              How many lines in total




              Not sure that I understood you request correctly. e.g. this will output results in the following format, showing the number of lines for each file:



              # wc -l `find /path/to/directory/ -type f`
              103 /dir/a.php
              378 /dir/b/c.xml
              132 /dir/d/e.xml
              613 total


              Alternatively, to output just the total number of new line characters without the file by file counts to following command can prove useful:



              # find /path/to/directory/ -type f -exec wc -l ; | awk 'total += $1 ENDprint total'
              613



              Most importantly, I need this in 'human readable format' eg.
              12,345,678 rather than 12345678




              Bash has a printf function built in:



              printf "%0.2fn" $T


              As always, there are many different methods that could be used to achieve the same results mentioned here.






              share|improve this answer













              How many lines are in each file.




              Use wc, originally for word count, I believe, but it can do lines, words, characters, bytes, and the longest line length. The -l option tells it to count lines.



              wc -l <filename>


              This will output the number of lines in :



              $ wc -l /dir/file.txt
              32724 /dir/file.txt


              You can also pipe data to wc as well:



              $ cat /dir/file.txt | wc -l
              32724
              $ curl google.com --silent | wc -l
              63



              How many lines are in directory.




              Try:



              find . -name '*.pl' | xargs wc -l


              another one-liner:



              ( find ./ -name '*.pl' -print0 | xargs -0 cat ) | wc -l


              BTW, wc command counts new lines codes, not lines. When last line in the file does not end with new line code, this will not counted.



              You may use grep -c ^ , full example:



              #this example prints line count for all found files
              total=0
              find /path -type f -name "*.php" | while read FILE; do
              #you see use grep instead wc ! for properly counting
              count=$(grep -c ^ < "$FILE")
              echo "$FILE has $count lines"
              let total=total+count #in bash, you can convert this for another shell
              done
              echo TOTAL LINES COUNTED: $total



              How many lines in total




              Not sure that I understood you request correctly. e.g. this will output results in the following format, showing the number of lines for each file:



              # wc -l `find /path/to/directory/ -type f`
              103 /dir/a.php
              378 /dir/b/c.xml
              132 /dir/d/e.xml
              613 total


              Alternatively, to output just the total number of new line characters without the file by file counts to following command can prove useful:



              # find /path/to/directory/ -type f -exec wc -l ; | awk 'total += $1 ENDprint total'
              613



              Most importantly, I need this in 'human readable format' eg.
              12,345,678 rather than 12345678




              Bash has a printf function built in:



              printf "%0.2fn" $T


              As always, there are many different methods that could be used to achieve the same results mentioned here.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Feb 7 '16 at 19:49









              malyy

              96747




              96747











              • By the way, how do I use printf in your examples? I tried to pipe to it from wc -l, but it didn't work.
                – Hexatonic
                Feb 8 '16 at 2:12










              • try > find . -name '*.pl' | xargs wc -l | awk 'printf ("%0.2f ", $1) print $2' change the output of 'printf' for your needs
                – malyy
                Feb 8 '16 at 15:34










              • This doesn't add commas to the number to make it more human readable though. It just adds a zeros to the end.
                – Hexatonic
                Feb 8 '16 at 16:05










              • echo 1000000000000 | xargs printf "%'dn" 1,000,000,000,000
                – Hexatonic
                Feb 8 '16 at 16:07






              • 1




                @Hexatonic printf doesn't read its arguments from stdin, but rather from the command line (compare piping to echo vs piping to cat; cat reads from stdin, echo doesn't). Instead, use printf "$(find ... | xargs ...)" to supply the output as arguments to printf.
                – BallpointBen
                Aug 21 at 22:02
















              • By the way, how do I use printf in your examples? I tried to pipe to it from wc -l, but it didn't work.
                – Hexatonic
                Feb 8 '16 at 2:12










              • try > find . -name '*.pl' | xargs wc -l | awk 'printf ("%0.2f ", $1) print $2' change the output of 'printf' for your needs
                – malyy
                Feb 8 '16 at 15:34










              • This doesn't add commas to the number to make it more human readable though. It just adds a zeros to the end.
                – Hexatonic
                Feb 8 '16 at 16:05










              • echo 1000000000000 | xargs printf "%'dn" 1,000,000,000,000
                – Hexatonic
                Feb 8 '16 at 16:07






              • 1




                @Hexatonic printf doesn't read its arguments from stdin, but rather from the command line (compare piping to echo vs piping to cat; cat reads from stdin, echo doesn't). Instead, use printf "$(find ... | xargs ...)" to supply the output as arguments to printf.
                – BallpointBen
                Aug 21 at 22:02















              By the way, how do I use printf in your examples? I tried to pipe to it from wc -l, but it didn't work.
              – Hexatonic
              Feb 8 '16 at 2:12




              By the way, how do I use printf in your examples? I tried to pipe to it from wc -l, but it didn't work.
              – Hexatonic
              Feb 8 '16 at 2:12












              try > find . -name '*.pl' | xargs wc -l | awk 'printf ("%0.2f ", $1) print $2' change the output of 'printf' for your needs
              – malyy
              Feb 8 '16 at 15:34




              try > find . -name '*.pl' | xargs wc -l | awk 'printf ("%0.2f ", $1) print $2' change the output of 'printf' for your needs
              – malyy
              Feb 8 '16 at 15:34












              This doesn't add commas to the number to make it more human readable though. It just adds a zeros to the end.
              – Hexatonic
              Feb 8 '16 at 16:05




              This doesn't add commas to the number to make it more human readable though. It just adds a zeros to the end.
              – Hexatonic
              Feb 8 '16 at 16:05












              echo 1000000000000 | xargs printf "%'dn" 1,000,000,000,000
              – Hexatonic
              Feb 8 '16 at 16:07




              echo 1000000000000 | xargs printf "%'dn" 1,000,000,000,000
              – Hexatonic
              Feb 8 '16 at 16:07




              1




              1




              @Hexatonic printf doesn't read its arguments from stdin, but rather from the command line (compare piping to echo vs piping to cat; cat reads from stdin, echo doesn't). Instead, use printf "$(find ... | xargs ...)" to supply the output as arguments to printf.
              – BallpointBen
              Aug 21 at 22:02




              @Hexatonic printf doesn't read its arguments from stdin, but rather from the command line (compare piping to echo vs piping to cat; cat reads from stdin, echo doesn't). Instead, use printf "$(find ... | xargs ...)" to supply the output as arguments to printf.
              – BallpointBen
              Aug 21 at 22:02












              up vote
              5
              down vote













              In many cases combining the wc command and the wildcard * may be enough.

              If all your files are in a single directory you can call:



              wc -l src/*


              You can also list several files and directories:



              wc -l file.txt readme src/* include/*


              This command will show a list of the files and their number of lines.

              The last line will be the sum of the lines from all files.




              To count all files in a directory recursively:



              First, enable globstar by adding shopt -s globstar to your .bash_profile. Support for globstar requires Bash ≥ 4.x which can be installed with brew install bash if needed. You can check your version with bash --version.



              Then run:



              wc -l **/*


              Note that this output will be incorrect if globstar is not enabled.






              share|improve this answer






















              • And for counting files in the currrent directory recursively: wc -l **/*
                – Taylor Edmiston
                Mar 31 at 18:35










              • @TaylorEdmiston For me (on Mac) that only counts the files exactly one directory down. It skips the files in the current directory, and for any instance that would be more than one directory deep it warns that it's a directory: "wc: parent_dir/child_dir: read: Is a directory"
                – M. Justin
                Sep 16 at 5:56











              • @Thomio It requires globstar to be enabled. On macOS, I believe it is disabled out of the box. I've just sent an edit to your answer that adds the command and how to enable globstar.
                – Taylor Edmiston
                2 days ago














              up vote
              5
              down vote













              In many cases combining the wc command and the wildcard * may be enough.

              If all your files are in a single directory you can call:



              wc -l src/*


              You can also list several files and directories:



              wc -l file.txt readme src/* include/*


              This command will show a list of the files and their number of lines.

              The last line will be the sum of the lines from all files.




              To count all files in a directory recursively:



              First, enable globstar by adding shopt -s globstar to your .bash_profile. Support for globstar requires Bash ≥ 4.x which can be installed with brew install bash if needed. You can check your version with bash --version.



              Then run:



              wc -l **/*


              Note that this output will be incorrect if globstar is not enabled.






              share|improve this answer






















              • And for counting files in the currrent directory recursively: wc -l **/*
                – Taylor Edmiston
                Mar 31 at 18:35










              • @TaylorEdmiston For me (on Mac) that only counts the files exactly one directory down. It skips the files in the current directory, and for any instance that would be more than one directory deep it warns that it's a directory: "wc: parent_dir/child_dir: read: Is a directory"
                – M. Justin
                Sep 16 at 5:56











              • @Thomio It requires globstar to be enabled. On macOS, I believe it is disabled out of the box. I've just sent an edit to your answer that adds the command and how to enable globstar.
                – Taylor Edmiston
                2 days ago












              up vote
              5
              down vote










              up vote
              5
              down vote









              In many cases combining the wc command and the wildcard * may be enough.

              If all your files are in a single directory you can call:



              wc -l src/*


              You can also list several files and directories:



              wc -l file.txt readme src/* include/*


              This command will show a list of the files and their number of lines.

              The last line will be the sum of the lines from all files.




              To count all files in a directory recursively:



              First, enable globstar by adding shopt -s globstar to your .bash_profile. Support for globstar requires Bash ≥ 4.x which can be installed with brew install bash if needed. You can check your version with bash --version.



              Then run:



              wc -l **/*


              Note that this output will be incorrect if globstar is not enabled.






              share|improve this answer














              In many cases combining the wc command and the wildcard * may be enough.

              If all your files are in a single directory you can call:



              wc -l src/*


              You can also list several files and directories:



              wc -l file.txt readme src/* include/*


              This command will show a list of the files and their number of lines.

              The last line will be the sum of the lines from all files.




              To count all files in a directory recursively:



              First, enable globstar by adding shopt -s globstar to your .bash_profile. Support for globstar requires Bash ≥ 4.x which can be installed with brew install bash if needed. You can check your version with bash --version.



              Then run:



              wc -l **/*


              Note that this output will be incorrect if globstar is not enabled.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 2 days ago









              Taylor Edmiston

              1034




              1034










              answered Jan 30 '17 at 19:22









              Thomio

              15113




              15113











              • And for counting files in the currrent directory recursively: wc -l **/*
                – Taylor Edmiston
                Mar 31 at 18:35










              • @TaylorEdmiston For me (on Mac) that only counts the files exactly one directory down. It skips the files in the current directory, and for any instance that would be more than one directory deep it warns that it's a directory: "wc: parent_dir/child_dir: read: Is a directory"
                – M. Justin
                Sep 16 at 5:56











              • @Thomio It requires globstar to be enabled. On macOS, I believe it is disabled out of the box. I've just sent an edit to your answer that adds the command and how to enable globstar.
                – Taylor Edmiston
                2 days ago
















              • And for counting files in the currrent directory recursively: wc -l **/*
                – Taylor Edmiston
                Mar 31 at 18:35










              • @TaylorEdmiston For me (on Mac) that only counts the files exactly one directory down. It skips the files in the current directory, and for any instance that would be more than one directory deep it warns that it's a directory: "wc: parent_dir/child_dir: read: Is a directory"
                – M. Justin
                Sep 16 at 5:56











              • @Thomio It requires globstar to be enabled. On macOS, I believe it is disabled out of the box. I've just sent an edit to your answer that adds the command and how to enable globstar.
                – Taylor Edmiston
                2 days ago















              And for counting files in the currrent directory recursively: wc -l **/*
              – Taylor Edmiston
              Mar 31 at 18:35




              And for counting files in the currrent directory recursively: wc -l **/*
              – Taylor Edmiston
              Mar 31 at 18:35












              @TaylorEdmiston For me (on Mac) that only counts the files exactly one directory down. It skips the files in the current directory, and for any instance that would be more than one directory deep it warns that it's a directory: "wc: parent_dir/child_dir: read: Is a directory"
              – M. Justin
              Sep 16 at 5:56





              @TaylorEdmiston For me (on Mac) that only counts the files exactly one directory down. It skips the files in the current directory, and for any instance that would be more than one directory deep it warns that it's a directory: "wc: parent_dir/child_dir: read: Is a directory"
              – M. Justin
              Sep 16 at 5:56













              @Thomio It requires globstar to be enabled. On macOS, I believe it is disabled out of the box. I've just sent an edit to your answer that adds the command and how to enable globstar.
              – Taylor Edmiston
              2 days ago




              @Thomio It requires globstar to be enabled. On macOS, I believe it is disabled out of the box. I've just sent an edit to your answer that adds the command and how to enable globstar.
              – Taylor Edmiston
              2 days ago










              up vote
              1
              down vote













              a bit late to the game, but I got a bunch of argument errors with the above due to the size of the dir. This worked for me:



              for i in $(find . -type f); do wc -l $i; done >> /home/counts.txt






              share|improve this answer
























                up vote
                1
                down vote













                a bit late to the game, but I got a bunch of argument errors with the above due to the size of the dir. This worked for me:



                for i in $(find . -type f); do wc -l $i; done >> /home/counts.txt






                share|improve this answer






















                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  a bit late to the game, but I got a bunch of argument errors with the above due to the size of the dir. This worked for me:



                  for i in $(find . -type f); do wc -l $i; done >> /home/counts.txt






                  share|improve this answer












                  a bit late to the game, but I got a bunch of argument errors with the above due to the size of the dir. This worked for me:



                  for i in $(find . -type f); do wc -l $i; done >> /home/counts.txt







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 16 at 23:50









                  Ron Paulfan

                  111




                  111




















                      up vote
                      0
                      down vote













                      This command will give list of lines code in each directory:



                      find . -name '*.*' -type f | xargs wc -l





                      share|improve this answer


























                        up vote
                        0
                        down vote













                        This command will give list of lines code in each directory:



                        find . -name '*.*' -type f | xargs wc -l





                        share|improve this answer
























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          This command will give list of lines code in each directory:



                          find . -name '*.*' -type f | xargs wc -l





                          share|improve this answer














                          This command will give list of lines code in each directory:



                          find . -name '*.*' -type f | xargs wc -l






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 8 at 14:43









                          peterh

                          4,00292755




                          4,00292755










                          answered Mar 8 at 14:24









                          Suresh.A

                          1




                          1



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f260630%2fhow-do-you-list-number-of-lines-of-every-file-in-a-directory-in-human-readable-f%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?