How To Wiki
No edit summary
Line 10: Line 10:
 
</pre>
 
</pre>
   
  +
You can put this command in a
You can put this command in a [[bash script]] or create and [[alias]]<div id="wikia-credits"><br /><br /><small>From [http://howto.wikia.com HowTo Wiki], a [http://www.wikia.com Wikia] wiki.</small></div>
 
  +
[[bash script]] or create and [[alias]]
 
<div id="wikia-credits"><br /><br /><small>From [http://howto.wikia.com HowTo Wiki], a [http://www.wikia.com Wikia] wiki.</small></div>
   
  +
This is completely pointless. A much simpler way to do this is:
   
  +
<pre>
  +
wc -l *.php
  +
</pre>
   
  +
This will output the line count for each file, but with a total at the end as well.
 
[[Category:Howto]]
 
[[Category:Howto]]

Revision as of 18:10, 27 September 2010

You can use find and awk to counting the total number of lines in multiple files

Solution

Using the usual GNU tools, you can write the following script (replace "*.java" with your language file type):

find . -name "*.java" -exec wc -l '{}' \; | awk '{ sum += $1 } END { print sum }'

You can put this command in a bash script or create and alias



From HowTo Wiki, a Wikia wiki.

This is completely pointless. A much simpler way to do this is:

wc -l *.php

This will output the line count for each file, but with a total at the end as well.