grep recursively against known filenames

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 "" --include=2021-08-30* --recursive 
This will grep recursively for the phrase “” but only in logfiles that start with 2021-08-30*