Entrepreneur Geek

Nirav Mehta on life, technology and future

Finding number of lines in files recursively

without comments

I wanted to find the number of lines from a set of files – spread out in nested directories. The shell command “wc” is best for finding number of words / lines in files but it does not have an argument for recursive searching.

Here’s a quick shell command sequence that will find you the line count from all files in a directory – recursively.

find /topleveldirectory/ -type f -exec wc -l {} \; | awk '{total += $1} END{print total}'

Replace “/topleveldirectory/” with your directory of choice. Leave it as “.” to find from current directory and below.

Found on Unix.com

Related posts:

  1. Recursively unlock files on Mac OS X I copied some songs from a CD and ended up...

Written by Nirav

December 25th, 2009 at 10:07 am

Posted in Apple, GNU/Linux

Tagged with , ,

 

Leave a Reply