Skip to content
CodeItRaw
Terminal Basics

Lesson 4/5

Log files run to thousands of lines, and usually only the end or certain lines concern you. cat dumps the lot; there are better tools: head shows a few lines from the start and tail from the end, and grep picks the lines that contain a word.

head -n 5 access.log
tail -n 20 access.log
grep WARN app.log
grep -i timeout app.log
grep -c WARN app.log
-n says how many lines you want. grep word file writes the lines where the word occurs; -i ignores upper and lower case, -c counts the lines instead of writing them, -v gives the lines where the word does not occur.

grep finds the word wherever it is on the line, and what you look for may also be part of a word: grep ERR brings both the ERROR and the STDERR lines. If the text you search for has a space, put it in quotes: grep "disk full" app.log.

Tasks

Tasks open in order. Solve them all and the next lesson opens.

This lesson's tasks open when the lessons before it are finished. You can read the explanation now.Go to the current lesson

  1. 01

    The last lines

    Terminal task

  2. 02

    Find the errors

    Terminal task

If you would rather not wait for the order, every problem is open without locks: Problem list