Link to home
Start Free TrialLog in
Avatar of rudy201
rudy201

asked on

Find files that contain a string, and display line counts

I use below to list all P* files that contain "foo"

find . -type f -name "P*" -exec grep -l foo {} \;

How should I change this command to also display line count next to each file name?
Avatar of Tintin
Tintin

find . -type f -name "P*" | xargs grep -c foo

or

grep -rc P*
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
find basedir1 basedir2 -type f -name P* -print0 | xargs -0 wc -l
(this one starts one wc command for many arguments, a bit more efficient than re-executing for each file)