Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
11-12-2005, 03:24 PM
|
#1
|
Senior Member
Registered: Jun 2003
Location: UK
Distribution: Gentoo
Posts: 1,288
Rep:
|
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.
|
|
|
11-12-2005, 03:54 PM
|
#2
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
wc -l *
|
|
|
11-12-2005, 04:02 PM
|
#3
|
Senior Member
Registered: Jun 2003
Location: UK
Distribution: Gentoo
Posts: 1,288
Original Poster
Rep:
|
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..
|
|
|
11-12-2005, 04:28 PM
|
#4
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
"lines of code in that folder"...
anyway... if you want it to recurse, run it through find. find -type f -exec wc -l {} \;
|
|
|
11-12-2005, 04:29 PM
|
#5
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
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
|
|
|
11-12-2005, 04:42 PM
|
#6
|
Senior Member
Registered: Jun 2003
Location: UK
Distribution: Gentoo
Posts: 1,288
Original Poster
Rep:
|
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 05:24 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|