in Technology

Finding number of lines in files recursively

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

Write a Comment

Comment