A pipe is what turns a pile of small commands into a tool. The count-and-rank pattern below is worth knowing by heart, because it answers a question that comes up constantly.
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.
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.
Count and rank the busiest address
This writes a small access log, pulls the first column out of it, sorts the addresses, counts the repeats, and orders the result.
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 "10.0.0.2 - - GET /index.html\n10.0.0.1 - - GET /about.html\n10.0.0.2 - - GET /index.html\n10.0.0.3 - - GET /index.html\n10.0.0.2 - - GET /about.html\n" > ~/access.log; cut -d " " -f1 ~/access.log | sort | uniq -c | sort -n
Three lines should come out, each with a count in front of an address.
the busiest address is counted as 3
the quieter addresses are counted as 1
all three addresses appear
What a good answer looks like
Three lines, each a count followed by an address, in ascending order of count: 1 for 10.0.0.1, 1 for 10.0.0.3, and 3 for 10.0.0.2. That tells you 10.0.0.2 is the busiest, which is the answer the whole pipeline was built to produce. The order matters: cut takes the column, sort groups the repeats, uniq -c counts each group, and the final sort -n puts the biggest count last so it is easy to read. Swap that last one to sort -nr and the busiest address comes first instead.
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.