With grep, how do I display only the filenames with hits, not the contents?
- User
With grep, how do I display only the filenames with hits, not the contents?
Assistant
To display only the filenames that contain matches, and not the matching lines themselves, you can use the
-l(lowercase L) option in grep.For example:
grep -l pattern *This will search for
patternin the files listed (*matches all files in the current directory), and will print only the names of files that contain matches, one filename per line.The
-loption tells grep not to print the matching lines, only the filenames.A couple other useful options:
-r- Search recursively through directories-i- Case insensitive search
So to recursively search all files for "foo", only printing filenames:
grep -ril foo .The
.specifies the current directory to search recursively.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.