Pipes and redirection

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.

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 the | character do?
2 Why must sort come before uniq -c?
3 What is the difference between > and >>?
4 What does 2>/dev/null do?

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
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