Binary Expressions

2007-11-9

Finding The Total Lines Within Files

Filed under: — The Warden @ 5:06 pm

I have learned by using the “find”, “wc” and “awk” commands one can find the total number of lines within files of a given directory and sub-directories. Thanks to NicM on IRC server Freenode channel #OpenBSD for his solution below.

Solution
find /path/blah -type f -name ‘*.php’|while read i; do wc -l <$i; done|awk ‘BEGIN { x=0 }; { x+=$1 }; END { print x }’

Note: Shell must be bourne-compatible.

Leave a Reply

Take back your mailbox - CAUCE.org

Powered By Wordpress PHP: Hypertext Preprocessor MySQL Powered Download Juice, the cross-platform podcast receiver
Proud To Be Canadian Get Firefox Valid XHTML Valid CSS
<NO>OOXML Logo


24 queries. 0.262 seconds.
Copyright © 2004 - 2005 by Adam Douglas