LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 11-12-2005, 03:24 PM   #1
xushi
Senior Member
 
Registered: Jun 2003
Location: UK
Distribution: Gentoo
Posts: 1,288

Rep: Reputation: 45
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.
 
Old 11-12-2005, 03:54 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,374

Rep: Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962
wc -l *
 
Old 11-12-2005, 04:02 PM   #3
xushi
Senior Member
 
Registered: Jun 2003
Location: UK
Distribution: Gentoo
Posts: 1,288

Original Poster
Rep: Reputation: 45
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..
 
Old 11-12-2005, 04:28 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,374

Rep: Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962
"lines of code in that folder"...

anyway... if you want it to recurse, run it through find. find -type f -exec wc -l {} \;
 
Old 11-12-2005, 04:29 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,962
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
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
 
Old 11-12-2005, 04:42 PM   #6
xushi
Senior Member
 
Registered: Jun 2003
Location: UK
Distribution: Gentoo
Posts: 1,288

Original Poster
Rep: Reputation: 45
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,
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Scripting: How to pick lines out of files by line number. Louie55 Programming 3 03-22-2005 06:18 PM
rrdtool total traffic count burn0ut Linux - Networking 3 02-02-2005 07:56 AM
command to count how many lines in a file? dr_zayus69 Linux - Software 3 01-06-2005 10:42 AM
How to count how many lines of code my project is? The_Nerd Programming 4 08-30-2004 08:26 PM
Command to list total number of files. WillieB_72 Linux - General 3 01-29-2003 09:25 PM


All times are GMT -5. The time now is 06:16 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration