grep recursively against known filenames

(Last Updated On: September 7, 2021)

Sometimes you need to grep for a phrase in an unwieldy directory. Recursion makes this easy, but it could be slow if there are a lot of files.

If you know part of the filename you can limit which files are grepped by using a glob include. There is also an exclude option.

I frequently need to search for an IP address in our syslog server. I’m not sure where that address might show up, but since the syslog files are datetime stamped, I can restrict the logfiles that are grepped.

grep "10.9.8.7" --include=2021-08-30* --recursive 
This will grep recursively for the phrase “10.9.8.7” but only in logfiles that start with 2021-08-30*

Leave a Reply