Linux script for searching logs

I have 31 log files in a directory.  I want to search each log file for a specific string.  It would be nice to search all 30 with a single command.  For output I would just like a count of the matches.  How can I accomplish this?

Directory name: /logs
Log file naming convention:
system.log  -  (today's log)
system.log.* -  (previous 30 day's logs where * is the number 1-30)
LVL 7
southpau1Asked:
Who is Participating?
 
woolmilkporcConnect With a Mentor Commented:
To get only a total count of matches (a single number):

grep -hc "specific string" system.log* | awk '{s+=$1} END {print s}'
0
 
woolmilkporcConnect With a Mentor Commented:
cd /logs
grep -c "specific string" system.log*

gives a count of matches per file.
0
 
farzanjCommented:
Try
grep "STRING" system.log*

Open in new window


Use -c option to count matches
0
All Courses

From novice to tech pro — start learning today.