I'm looking for files that contain a string. My command:grep -rwl '/path/' -e stringI want to limit the result to paths that contain a different string. I can do it like this:grep -rwl '/path/' -e string | grep 'path_string'I would like to optimize the execution, if possible, by only looking at paths with the 'path_string' to begin with. How can I accomplish this?
Filtered List of Files Containing String
grep;search
You could use find with -path e.g.find /path -path '*path_string*' -type f -exec grep -qw 'string' {} \; -printThis will search under /path for file names matching1 shell pattern *path_string* and run grep only on those files, printing their names if successful.1: the pattern match is applied to the whole file name starting from /path/