Middle
Write a command or script that finds all files with the extension .log in the current directory containing the word error, and outputs only the names of these files.
sobes.tech AI
Answer from AI
You can use the grep command with the -l option, which outputs only the filenames where a match is found:
grep -l "error" *.log
If you need to search recursively in all subdirectories:
grep -rl --include="*.log" "error" .
Here:
-r— recursive search-l— outputs only filenames--include="*.log"— restricts search to files with.logextension.— current directory