Linux Labs

First steps / Stage 12 of 15

Pipelines: an answer from several commands

Not running Starting usually ~20 s
Leave the lesson

Step 1 of 7 · on a machine · 6 min

Who sent the most

What you will learn

  • Feed one command's output into another's input with |.
  • Count repeats in a log column with cut, sort and uniq -c together.
  • Build a pipeline one link at a time and save the answer to a file.

The site was slow overnight. Your manager asks which address sent the most requests. The web server log, access.log, has 5000 lines, one per request, and the first word of each line is the client's address. A colleague sent a command that answers this kind of question — run it.

Exercise · look

Run your colleague's command

In ~/pipe-lab, look at the first two lines of the log, then run your colleague's command.

First, predict

What will your colleague's command 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
Check yourself 1 question

Only cut was given the file name access.log. Where did sort, uniq and head get their lines?

  • No new files appeared in the directory — check with ls. The lines went from command to command directly.

  • Three lines reached the screen, while sort received 5000 addresses. Between the commands the lines bypassed the screen.

  • With no file name, sort, uniq and head open no files. Run sort with no arguments: it waits for text from the keyboard; Ctrl+C gets you out.

The | sign passed each command's output to the input of the next.

Ubuntu 24.04
Loading…