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
Personally I'd find and grep. I know newer greps support recursion but find would be my goto
Replying to @hal_pomeranz
find /path/to/directory -type f | egrep "string"
1
Replying to @hal_pomeranz
grep -Ril ’string’ /path 2>/dev/null
Replying to @hal_pomeranz
1. to find strings in filenames: find dir/ -iname "*string*" 2. to find files, containing the strings: rg string (RipGrep is the best @burntsushi5)
1