Hey everyone! I'm currently taking a course on Linux and I've run into a problem while using the grep command. I'm trying to find the word 'ERROR' (case-insensitive) across multiple .log files that are located in various directories. I've attempted using the 'grep -r' command, but it hasn't worked out for me. With a midterm exam coming up tomorrow, I really need to figure this out. Any help would be greatly appreciated!
2 Answers
To search for 'ERROR' in multiple .log files, try this command: `grep -Rin --include='*.log' 'error' /path/to/search`. Here’s what it does: '-R' enables recursive searching, '-i' makes the search case-insensitive, and '-n' shows line numbers. If the 'grep -r' command didn’t work, it might be due to permissions or being in the wrong directory. You can redirect errors using `2>/dev/null` to avoid permission error messages.
If you need to save the results to a new file and only display the number of lines saved, you can indeed use `grep -Rin --include='*.log' 'error' /path/to/search > path/to/destination`. To count the lines in the new file and display that, try piping to `wc -l`, but make sure you’re directing it correctly. If it's showing 0, check that there are actually matching lines in the files you're searching through.

Related Questions
Can't Load PhpMyadmin On After Server Update
Redirect www to non-www in Apache Conf
How To Check If Your SSL Cert Is SHA 1
Windows TrackPad Gestures