World map

 

BM: Baca dalam Bahasa Melayu

World L1: The Shophouse

Pipes and redirects

You will learn: to chain small commands with | and save their output to files.

Checked with Linux (Debian 13) on 1 Nov 2026

The problem

The boss wants a list: each dish sold today, best seller first. No single command does that. What now?

Pick one answer.

Watch

You are you in /home/you/kedai/counter. 1 things here. Services: cron running, ssh running, nginx running.

You are hereyou@kedai:~/kedai/counter$

Folder ~/kedai/counter

  • orders.log (file)-rw-r--r--

Services

  • cronrunningstarts at boot
  • sshrunningstarts at boot
  • nginxrunningstarts at boot

The pipe (|): A conveyor belt between two commands: the first one's output becomes the next one's input. | is a conveyor belt. grep’s lines ride along to wc -l, which counts them. Answer: 3 unpaid.

Try it

Build the best-seller belt. Put the four stations in order.

First station at the top. Put these in order. Use the arrows, or drag.

  • sort: line up the same dishes together
  • sort -rn: biggest number first
  • cut -d" " -f3 orders.log: keep only the dish column
  • uniq -c: count each group

Try it

Now run the whole belt in one line:

cut -d" " -f3 orders.log | sort | uniq -c | sort -rn

You are you in /home/you/kedai/counter. 1 things here. Services: cron running, ssh running, nginx running.

You are hereyou@kedai:~/kedai/counter$

Folder ~/kedai/counter

  • orders.log (file)-rw-r--r--

Services

  • cronrunningstarts at boot
  • sshrunningstarts at boot
  • nginxrunningstarts at boot

Predict

unpaid.txt holds 3 lines. You type echo oops > unpaid.txt. What is in the file now?

Pick one answer.

Try it

Save every unpaid order into a new file, a redirect: grep -i unpaid orders.log > unpaid.txt.

You are you in /home/you/kedai/counter. 1 things here. Services: cron running, ssh running, nginx running.

You are hereyou@kedai:~/kedai/counter$

Folder ~/kedai/counter

  • orders.log (file)-rw-r--r--

Services

  • cronrunningstarts at boot
  • sshrunningstarts at boot
  • nginxrunningstarts at boot

Check

Three arrows. Which one fits each job?

Drag a card into a box. Or tap the card, then tap the box.

        You did it!

        You can now chain commands with pipes and save output to files.

        Go deeper (optional)

        2> /dev/null throws error lines away. cmd > all.txt 2>&1 saves both kinds. tee report.txt shows the lines and saves them too. < feeds a file in: sort < today.txt.

        Real rep (optional), on your own machine:

        Real mission

        1. grep bash /etc/passwd | wc -l
        2. ps aux > procs.txt
        3. head -n 5 procs.txt

        0 of 3 steps done · Your ticks are saved.