A log file can have thousands of lines. Usually, you need only a few: the lines about one error, one order, one name. grep finds them.
grep reads a file and writes each line that has the text you give it:
learner@tidepool:~$ cat shop.log
08:00 INFO shop started
08:14 INFO order 1001 saved
09:30 ERROR printer not found
10:12 INFO order 1002 saved
learner@tidepool:~$ grep ERROR shop.log
09:30 ERROR printer not foundgrep does not change the file. It only reads it.
Many log files put a word at the start of each line to show how serious the event is: INFO for a normal event, WARN for a warning, ERROR for a problem. That makes them easy to find with grep.
The text can be part of a word
grep finds the text anywhere in a line, also inside a longer word. grep order finds order and also orders.
Uppercase and lowercase are different
grep ERROR does not find Error or error. The next lesson shows how to change this.
Text with spaces
Put text with spaces in quotes, so that it is one argument:
learner@tidepool:~$ grep "order 1001" shop.log
08:14 INFO order 1001 savedNo match
When no line has the text, grep writes nothing.