Lesson 97 taught you ls, grep, and find. This lab is where you use them on a real log. You get a six-line access log, you count the errors, you name the busiest address, and you write the answers into a report file. By the end you have a report you can show someone, and you know which field holds the status code, because you got it wrong once and fixed it.
Difficulty: Beginner · Know this first: Lesson 97 — Linux for Engineers; a Linux terminal (WSL2 on Windows works)
Every hop charges rent in milliseconds. The bar below is a worked example for this lesson's scenario — not a measurement from a live system — but the shape is honest: on a cache hit the trip is almost free, on a miss the kitchen eats the budget. Step through the lesson or switch the scenario and watch the bar change.
Extra diagram · from scratch to master
Start with one folder. Add one box at a time until the report is written and checked.
The budget bar above shows three fixed stories. This simulator lets you write your own. Move a slider and watch the counting and the total change in the budget bar, in the hop timings, and in the total. The numbers are a teaching example, not live measurements. The shape is the lesson: more lines means more counting, and the wrong field costs a rewrite.
How many lines the log holds. Every line is counted by awk, so more lines means a longer counting hop.
How many lines hold a 500 status. More errors means more lines to check in the report, and more to explain.
How many times the report is rewritten because the field number was wrong. Each rewrite costs about 2 min.
Try this: (1) Set lines to 6, errors to 2, rewrites to 0. The count is about 1 min, the check about 1 min, the write about 1 min, and the total is about 8 min. (2) Set all three to the worst end: 5,000 lines, 500 errors, 3 rewrites. The count is about 6 min, the check about 11 min, the write about 7 min, and the total is about 29 min. Same commands. Only the inputs changed.
Three questions. No score is saved anywhere — this is just you against the material.
Here is the counting pipeline from this lab, ready to edit. Change it, then run the check. The check looks for the three things a working count needs: awk printing a field, sort, and uniq -c. It also fails the line if it reads field 9 as the status.
Try breaking it on purpose: change $8 to $9, or delete the sort. Run the check and watch it fail. Then press Reset and try a change that keeps it passing, like counting field 1 for the top talker.
Expected output when it passes: The pipeline prints field 8, sorts, and counts the repeats. The counts are 3x200, 1x401, 2x500.
I take the same log four times here. First I look at it. Then I search it. Then I count it. Last I prove the answer with a report.
Flags in the next block, letter by letter. I read every flag out loud before I run a command I copied. A flag I cannot explain is a flag I do not run yet.
ls with no flags lists names only. No sizes, no dates, no permissions. That is the plain view.ls -l is the long listing. The -l adds permissions, owner, group, size, and date for each entry. Without -l I cannot see how big a file is or when it changed.ls -a shows hidden files too, the ones whose names start with a dot. The -a means all. Without it, config files stay invisible.ls -h prints sizes in KB, MB, and GB instead of raw bytes. The -h means human readable. It only changes anything together with -l. On its own it does nothing, because the plain listing shows no sizes.ls -t sorts by modification time, newest first. The -t means time order. ls -r reverses whatever order is in force. With -t it puts the oldest file first. ls -lrth is all four letters at once: long, reverse, time order, human sizes. I use it when I want the most recently changed file at the bottom of the screen, right above my prompt.cat access.log prints the whole file. No flags. I use cat to read a short file from start to finish.head -2 access.log prints the first 2 lines. The -2 is the count. Without a number, head prints the first 10 lines. I use head to see the shape of a file before I count it.wc -l access.log counts the lines. The -l means lines. -w would count words and -c would count bytes. I run wc -l before I trust any answer from a file, because a count built on a short file is a wrong count.pwd prints the directory I am standing in. No flags. I run it when a command gives an empty answer, because the usual cause is standing in the wrong folder.Check it: run ls, then ls -l, then ls -lrth in the lab folder. Watch the sizes appear with -l and the order flip when -r joins -t. Then run wc -l access.log and see 6.
Definition: A log is a text file, one event per line. ls names the file, cat prints it, head prints the first lines, wc -l counts them. Nothing here needs a tool you do not already have.
Types:
Uses: I use this for any new file I have never seen. I look at it before I count it. Try it now: run head -2 on the lab log and point at the status code on one line.
Dimensions: At low volume everything is instant. What breaks first is the folder: running the commands in the wrong folder gives empty answers that look like real ones.
Flags in the next block, letter by letter. I read every flag out loud before I run a command I copied. A flag I cannot explain is a flag I do not run yet.
grep -c ' 500 ' access.log counts the matches instead of printing them. The -c means count. The spaces around 500 matter: without them, 500 would also match 1500 and 5000, and the count would be wrong.grep -n prints the line number with each match. The -n means number the lines. Without it, I get the matching line but not where it sits.grep -r searches a whole folder instead of one file. The -r means recursive, walk into subdirectories. Without it, grep on a directory refuses to search inside it.grep -i ignores case. The -i means case insensitive, so error matches ERROR. I add it when I am not sure how the log spells a word.grep -q prints nothing. The -q means quiet. The exit code is the whole answer: 0 when something matched, 1 when nothing did. I use it inside if in scripts, where output would only be noise.grep -E turns on extended regex. The -E means the pattern may use +, ?, and | without backslashes. Without it, the pipe means a plain pipe character and the pattern never matches.Check it: run grep -c ' 500 ' access.log and see 2. Then run grep -c '500' access.log without the spaces and see whether the count changes. The spaces are the lesson.
Definition: grep prints the lines that match a pattern. -c counts them instead of printing them. -r searches a folder. -n prints the line number. The exit code is 0 when something matched and 1 when nothing did.
Types:
Uses: I use grep when I know the words I am looking for: an error code, an address, a word in a message. Try it now: run grep -c ' 500 ' on the lab log and check the answer is 2.
Dimensions: As the log grows, grep stays fast, because it reads one line at a time. What breaks is a pattern that is too loose: '500' without spaces also matches 1500 and 5000.
Flags in the next block, letter by letter. I read every flag out loud before I run a command I copied. A flag I cannot explain is a flag I do not run yet.
awk '{print $8}' access.log prints the eighth field of every line. Fields are numbered from 1, split on spaces by default. $8 is the status code in this log because the fields line up that way. One wrong field number and every count after it is a lie that looks exact.awk '{print $8, $9}' access.log prints two fields. The comma puts a space between them. $9 is the byte count in this log.awk '$8==200 {s+=$9} END {print s}' access.log adds up the bytes for one status only. The $8==200 in front means run this block only on lines where field 8 is 200. The END block runs once at the end and prints the total. Without the condition, the sum would cover every status at once.sort with no flags sorts lines alphabetically. The pipeline needs it before uniq, because uniq only counts repeats that sit next to each other.uniq -c counts the repeats. The -c means count, and it prints the count in front of each line. Without -c, uniq only removes the duplicates and prints each line once.sort -nr sorts numbers biggest first. The -n means numeric order, so 10 sorts after 2 instead of before it. The -r means reverse, so the biggest count lands on top. Without -n, the counts sort as text and 10 lands above 2.sort -rn -k2 sorts by the second field, numbers biggest first. The -k2 means sort on field 2. Without it, sort uses the whole line, and a count of 200 would sort by its first digit, not its size.Check it: run the count pipeline, then run it without the first sort and watch the counts split. Then run sort -rn on the counts and sort -r without -n and compare where 10 lands.
Definition: awk splits each line into fields, numbered from 1. $8 is the eighth field. sort orders the lines. uniq -c counts the repeats, but only when the repeats sit next to each other, which is why sort comes first.
Types:
Uses: I use this when I need a summary, not a list: how many of each status, who made the most requests, how many bytes each status sent. Try it now: run the count pipeline from the Try it box and check the counts are 3, 1, and 2.
Dimensions: At ten times the lines, the pipeline still works, and the counting hop grows. What breaks is the field number: one wrong number and every count is a lie that looks exact.
Flags in the next block, letter by letter. I read every flag out loud before I run a command I copied. A flag I cannot explain is a flag I do not run yet.
cat report.txt prints the report I wrote. No flags. I read it back after writing it, because a report I never reread is a report I never checked.> report.txt writes output into a file, replacing what was there. The >> form appends instead of replacing. I use > for a fresh report and >> when I add one more section to a report that already exists. Mixing them up is how a report loses its first half.wc -l report.txt counts the lines in the report. The -l is the lines flag. I check the count before I send the report, because a report with zero lines is an empty file with a good name.Check it: write the report, then run wc -l report.txt and cat report.txt. Read every number in it and check it against the log with the commands from this lab before you call the lab done.
Definition: At this level the answer is not a number on a screen. It is a file someone else can check. The report holds the counts, the byte totals, and the top talker, and every number in it can be reproduced from the log with the commands in this lab.
Types:
Uses: I use this when the answer leaves my screen: a ticket, a handover, an incident note. Try it now: write report.txt from your own run and check every number against the log before you call the lab done.
Dimensions: At a hundred times the lines, the report is the same shape, and the commands are the same. What breaks is trust: a report nobody can reproduce is a guess with formatting.
Flags in the next block, letter by letter. I read every flag out loud before I run a command I copied. A flag I cannot explain is a flag I do not run yet.
wc -l access.log counts the lines. The -l is the lines flag. The answer should be 6, one per log line.awk '{print $8, $9}' access.log prints the status and the bytes for every line. $8 is the status, $9 is the bytes. Count the fields on the first line with your finger and the numbers line up.awk '$8==200 {s+=$9} END {print s}' access.log adds the bytes for the 200 lines only. The answer should be 3072, three lines at 1024 bytes each. If it is not 3072, the status field is wrong.for i in $(seq 1 800); do cat access.log; done > big.log builds a big log by copying the small one 800 times. The seq 1 800 prints the numbers 1 to 800. The $(...) pastes that list into the loop. The > big.log writes all 800 copies into one file. The wc -l big.log after it should print 4800.Check it: run awk '$8==200 {s+=$9} END {print s}' access.log and see 3072. Then build big.log and run the count pipeline on it. The counts should be 2400, 800, and 1600.
The log this lab uses, all six lines. Do this: save it as access.log in your lab folder, then run wc -l access.log. Expected output: 6 access.log.
192.168.1.10 - - [20/Nov/2026:10:00:01] "GET /home HTTP/1.1" 200 1024
192.168.1.11 - - [20/Nov/2026:10:00:02] "GET /api/users HTTP/1.1" 200 1024
192.168.1.10 - - [20/Nov/2026:10:00:03] "POST /api/login HTTP/1.1" 500 256
192.168.1.12 - - [20/Nov/2026:10:00:04] "GET /admin HTTP/1.1" 401 256
192.168.1.10 - - [20/Nov/2026:10:00:05] "GET /home HTTP/1.1" 200 1024
192.168.1.11 - - [20/Nov/2026:10:00:06] "GET /api/orders HTTP/1.1" 500 256
Count the fields on the first line with your finger. Field 1 is the address. Field 4 is the date. Fields 5, 6, and 7 are the request: method, path, protocol. Field 8 is the status. Field 9 is the bytes. That is why $8 is the status and $9 is the size. Do this: run awk '{print $8, $9}' access.log. Expected output: six lines of two numbers, starting 200 1024.
Bytes by status, the check that the counts are true. Do this: run awk '$8==200 {s+=$9} END {print s}' access.log. Expected output: 3072, three 200 lines at 1024 bytes each. The 500 lines add to 512 and the 401 line is 256. If the 200 total is not 3072, the status field is wrong.
Make a big log to feel the size change. Do this: run for i in $(seq 1 800); do cat access.log; done > big.log, then wc -l big.log. Expected output: 4800 big.log. Run the same count pipeline on big.log and expect 2400 200, 800 401, 1600 500. The commands are the same. Only the answers grow.
At 10x the lines, the shape holds and the numbers grow. At 100x, the design changes: the log gets rotated, compressed, and shipped to a central place, and the counting moves to a tool built for it. The field numbers never change, though. Field 8 is still the status.
A report I wrote said a service had zero errors for a week. The service had been failing all week. I had counted field 9, the byte count, as the status, so every line looked like a 1024 or a 256, and the error count came out zero. The report went to the team, and nobody checked it against the log, because the numbers looked exact.
Two things. First, I count the fields on one line before I write any awk command, every time. Second, I check every count against a grep count before the report leaves my screen. Try it now: run both the awk count and the grep count on the lab log and confirm they agree on 2.
Build a log report for a new log you make yourself. It must hold the status counts, the byte total for the 500 lines, the busiest address, and a redacted copy of the log. It passes when every number in the report matches a command you can rerun.
Success looks like this: report.txt holds four numbers that all match the log, the redacted copy starts every line with REDACTED, and the original log is byte-identical to the one you started with. If the grep count and the awk count disagree, the field number is wrong.
If grep finds nothing, check the pattern: ' 500 ' with spaces is not the same as '500'. If uniq -c gives 1 for everything, sort is missing or in the wrong place. If sed changed the file, you used -i by accident. If the byte total is wrong, the status and bytes fields are swapped.