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@kedai:~/kedai/counter$Folder ~/kedai/counter
- orders.log (file)
-rw-r--r--
Services
cronrunningstarts at bootsshrunningstarts at bootnginxrunningstarts 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@kedai:~/kedai/counter$Folder ~/kedai/counter
- orders.log (file)
-rw-r--r--
Services
cronrunningstarts at bootsshrunningstarts at bootnginxrunningstarts at boot
Hint
-d" " splits on spaces. -f3 keeps the third piece.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@kedai:~/kedai/counter$Folder ~/kedai/counter
- orders.log (file)
-rw-r--r--
Services
cronrunningstarts at bootsshrunningstarts at bootnginxrunningstarts at boot
Hint
Nothing prints: the lines went into the file.cat unpaid.txt shows them.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
grep bash /etc/passwd | wc -lps aux > procs.txthead -n 5 procs.txt
0 of 3 steps done · Your ticks are saved.
Bahasa Melayu
Bos mahu senarai: setiap hidangan terjual hari ini, paling laris dulu. Tiada satu arahan yang buat semua itu. Sekarang apa?
Pipe | ialah tali sawat. Baris dari grep bergerak ke wc -l, yang mengiranya. Jawapan: 3 belum bayar.
Bina tali sawat paling laris. Susun empat stesen ini.
Sekarang jalankan seluruh tali sawat dalam satu baris:
cut -d" " -f3 orders.log | sort | uniq -c | sort -rn
-d" " pecahkan ikut jarak. -f3 simpan bahagian ketiga.unpaid.txt ada 3 baris. Anda taip echo oops > unpaid.txt. Apa isi fail itu sekarang?
Simpan setiap pesanan belum bayar ke fail baru, satu redirect (hala semula): grep -i unpaid orders.log > unpaid.txt.
cat unpaid.txt tunjuk isinya.Tiga anak panah. Yang mana sesuai untuk setiap kerja?
Kini anda boleh sambung arahan dengan pipe dan simpan hasil ke fail.
You finished this before. Practice is always welcome!
Official docs: Bash manual: Pipelines · Bash manual: Redirections · sort (Debian 13 man page) · uniq (Debian 13 man page) · cut (Debian 13 man page)
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?