Grep is your friend :-)

Let’s say you have a running server and you notice that something in the server is not working well, so you want to search a log file for errors:

grep "error" somelogfile.log

This returned no results. This could be because grep being case-sensitive, let’s add the case-insensitivity flag:

grep –i "error" somelogfile.log

If the word “error” in any casing appears in the log file, you’ll see the relevant lines in the console. This is not the only way for the program to inform you there’s a problem, there are other words which might be relevant. You don’t want to search for them one by one:

grep –Ei "error|blocked|panic" somelogfile.log

The “E” flag indicates the use of regular expressions, which will allow you to use the pipe sign, dollar sign and other useful regex.

Now, you finally get the result you wanted, but you can only see one line of it and you want to know what it’s all about, so you can do this:

grep –A 10 –B 20 "Error" somelogfile.log