How to Use Grep for Case-Insensitive Searches in Multiple Log Files?

February 2, 2026 2 answers
Asked by no__special_skills
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!

Answers

!MindTheGapInTime
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.
Reply to this answer
dusk.to.daylight
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.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions