Linux Labs

First steps / Stage 12 of 15

Pipelines: an answer from several commands

Not running Starting usually ~20 s
Leave the lesson

Step 2 of 7 · on a machine · 6 min

One command's output, the next one's input

A | sign between commands builds a pipeline: the output of one command becomes the input of the next.

Besides the two exits from the previous lesson, a command has an input — standard input, stream 0. Commands that process text — grep, head, tail, sort — read a file when given its name, and standard input when given none. Such commands are called filters.

| connects stream 1 of the command on the left to stream 0 of the command on the right. Lines travel from command to command directly, with no files in between, and a pipeline can have as many links as you like.

wc with the -l option counts lines, so at the end of a pipeline it answers "how many". The lines with response code 404 are picked out by grep ' 404 ': the spaces around the number keep the code from being mistaken for part of another number.

Exercise · look

Count the 404 responses

In ~/pipe-lab, look at the first three log lines with code 404, then count all such lines.

First, predict

How many lines will the second command, with wc -l at the end, print?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Ubuntu 24.04
Loading…