From the Linux command-line you want to search a directory structure of files and return the paths to all files that contain a particular string. What command do you use? (Because we all need daily #Linux #DFIR #CommandLine #Trivia)

Nov 10, 2022 · 1:43 PM UTC

11
3
34
Props to 🐘feld@bikeshed.party for the first correct answer to yesterday's #Linux #DFIR #CommandLine #Trivia: "grep -rl string /path/to/files"
1
1
Honorable mention to 🐘PhilHagen@infosec.exchange for improving the answer with "rail grep": "grep -rail string /path/to/files". That will get you case-insensitive matching.
1
Interestingly, the "-a" and"-l" options are redundant here. "-a" normally gives you matching strings from non-ASCII files. But since we're only printing file names ("-l"), it doesn't matter.
1
1
We got several answers where people looked for a string in the file path rather than the file content. Props to JakubUrbanec for chiming in with: "find /path/to/files -iname "*string*"
Replying to @hal_pomeranz
nit pic.. find /path -name "*string*" finds when the files have that string... find /path -type f | grep string. which gives up all the paths containing string anywhere in the path.
Replying to @hal_pomeranz
It's been a while but wouldn't a rhino grep work? So if I wanted to look in /etc using the string "passwd", I'd do something like cd /etc; grep -rHino "passwd" to get the path names of files containing that string. Might have to filter out duplicates.
1
Replying to @hal_pomeranz
find / -iname <name of str> 2>/dev/null ??
Replying to @hal_pomeranz
Grep it all the way. grep -Rl /path/to -e 'string to match' or something similar. Many other grep options to help refine and tidy the output too.
Replying to @hal_pomeranz
grep -lR “$string_to_find” /path/to/search That’s a lowercase “L”