Menu
CoddyTech

Recap - Log Summary

Part of the Bash Scripting section of Coddy's Terminal journey. Lesson 26 of 39.

challenge icon

Challenge

Hard

Write summary.sh, a script that summarizes every web log under a folder. Each log line looks like this, with the path in field 7 and the status code in field 9:

10.0.0.5 - - [12/Mar/2026:10:01:22 +0000] "GET /index.html HTTP/1.1" 200 512
  1. The folder is the only argument. With any other number of arguments, print Usage: summary.sh FOLDER to stderr and exit with code 1.
  2. If the argument is not a folder, print Not a folder: NAME to stderr, with the argument in place of NAME, and exit with code 2.
  3. Read every file whose name ends in .log anywhere under the folder, nested folders included. Other files are not logs.
  4. Print Requests: N, the number of log lines.
  5. For each status code, print the code, a space and how many lines have it, one code per line, smallest code first.
  6. Print Top path: PATH (N), the path requested most often and how many times.

Try it: run bash summary.sh logs. It prints:

Requests: 8
200 5
404 2
500 1
Top path: /index.html (3)

Then run bash summary.sh logs/notes.txt: it prints Not a folder: logs/notes.txt and exits with code 2.

Try it yourself

Terminal

All lessons in Bash Scripting

Practice on your own: Terminal playground