LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   count total number of lines in several files (https://www.linuxquestions.org/questions/programming-9/count-total-number-of-lines-in-several-files-382506/)

xushi 11-12-2005 03:24 PM

count total number of lines in several files
 
Hi all,

I have a folder foo/ with many subfiles, subfolders and sub-subfiles/folders in it (a few hundred files and tens of folders), some that have code in them (.php, .html) and some miscalanious (gif, jpg, and so on).

Is there an easy and quick way or script i can use to count the total ammount of lines of code in that folder ?

Thanks.

acid_kewpie 11-12-2005 03:54 PM

wc -l *

xushi 11-12-2005 04:02 PM

Err, thanks, but not exactly,

That only counts the total number of lines the directory i'm on.. but it doesnt go through all the subdirectories and files in there too..

acid_kewpie 11-12-2005 04:28 PM

"lines of code in that folder"...

anyway... if you want it to recurse, run it through find. find -type f -exec wc -l {} \;

Tinkster 11-12-2005 04:29 PM

Code:

find -type f \( -iname "*.php" -o -iname "*.html" \) -exec wc -l {} \; | awk '{lines += $1 ; files += 1 ; print  }; END { print "Lines total is: ", lines ," in ", files ," files"}'

Something like this maybe?


Cheers,
Tink

xushi 11-12-2005 04:42 PM

Quote:

Originally posted by acid_kewpie
"lines of code in that folder"...
Yes, lines of code in that folder which contains several subfolders and files.

Quote:

Originally posted by acid_kewpie
anyway... if you want it to recurse, run it through find. find -type f -exec wc -l {} \; [/B]
Almost.. all that was missing is showing me the total, however,



Quote:

Originally posted by Tinkster
Code:

find -type f \( -iname "*.php" -o -iname "*.html" \) -exec wc -l {} \; | awk '{lines += $1 ; files += 1 ; print  }; END { print "Lines total is: ", lines ," in ", files ," files"}'
Something like this maybe?
Cheers,
Tink

Excellent, i think that did it! (just doing a few more tests) =)

Thanks all,


All times are GMT -5. The time now is 04:18 AM.