Reading and searching text

A log file is the most common thing you will be handed. Reading all of it is rarely the right move, so the useful skill is asking for the part you want.

4 questions 1 task Read the lesson

Questions

Each one is marked as you go, and the explanation arrives straight after, which is the part worth reading.

4 questions, marked as you go.

1 What does head -n 5 app.log print?
2 What does grep -c ERROR app.log print?
3 What does grep -r "ERROR" ~ do?
4 Why would you open a large file with less rather than cat?

Tasks

These need your own device. Run the command in Termux, then paste what it printed. The marking looks at what the output means, so spacing, version numbers and ordering do not matter. If you have not installed anything yet, the lesson covers the setup.

Find only the errors

This writes a small log file and then searches it, showing the line numbers of the matches rather than the whole file.

Run this in Termux On your own device. Nothing on this page executes it. The command runs in your terminal, and this box only reads what you paste back.

printf "INFO start\nERROR disk full\nINFO retry\nERROR timeout\n" > ~/app.log; grep -n ERROR ~/app.log
Marking your own work Both halves of this are checked in your browser, with no server involved, so nothing stops you from pasting output you did not run. The tasks are written so that the easiest way to pass one is to actually do it and read the result, which is the whole intention.

All sets Read the lesson