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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
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: 42,830
|
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: 42,830
|
"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: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,916
|
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,
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 05:26 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
|
|