Subj : Re: Getting the number of lines in a file To : alt.os.linux,comp.os.linux,alt.os.linux.mandrake From : John Cholewa Date : Fri Jul 23 2004 07:39 pm Joshua Beall writes: > What I really want to do is get the cumulative number of lines in many > files, recursing into subdirectories. I want to see how many lines of code > are in the PHP project I am working on right now. I don't know of any quick > way of doing this, and I have even thought about writing a quick PHP script > that will do it for me, but I don't want to do that if there is a bit of > shell wizardry that would be able to accomplish this for me. find . -type f -exec wc -l {} \; The dot (".") after the find can be replaced with the path of the directory in which you want to start looking. If you keep the dot, then it starts looking in the current directory. "-type f" means that it only looks at files (not directories and probably not symlinks). Then it passes the files that it finds to "wc", a word counting program, which will report the number of lines in each file because of the "-l". The "{}" is a magic placement thing that tells the find command where it should put the file names for the wc command. And the "\;" is just needed to tell find where to stop the wc call. That should work, no? Oh, wait, you wanted the cumulative.... Okay, there are better ways, but the following should work. Probably: find . -type f | sed 's/$/"/;s/^/"/' | xargs wc -l Done this way, "wc" is given all the files on the same line, and when that happens, wc gives a total. This may puke if you have a few thousand or more files in your project, though. Also, the "sed" stuff is there to put quotes around the file names, just in case there are spaces in any of them. -- -JC http://www.jc-news.com/coding/freedom/ .