BM: Baca dalam Bahasa Melayu
World L1: The Shophouse
Read files: cat, less, head, tail
You will learn: to read a whole file, its first lines, its newest lines, and to watch it grow.
Checked with Linux (Debian 13) on 1 Nov 2026
The problem
The counter keeps an order book, orders.log. It grows all day. You only need the newest orders. What do you do?
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
cat orders.log prints the whole file at once. Great for short files. A long one flies past your eyes.
Check
Pick the right tool for each job.
Drag a card into a box. Or tap the card, then tap the box.
Try it
Show only the last 3 orders: tail -n 3 orders.log.
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
-n 3 means “3 lines”.Predict
What does head -n 1 orders.log print?
Pick one answer.
Try it
Watch the book grow with tail -f orders.log. It holds the terminal. Stop it with Ctrl+C.
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
-f means “follow”: keep watching for new lines.Check
You opened a long log with less orders.log. You read enough. How do you leave?
Pick one answer.
You did it!
You can now read the top, the end, or a whole file.
Go deeper (optional)
In less, Space shows the next page and q quits. /sambal searches, and G jumps to the end. head and tail show 10 lines unless you say -n. cat -n numbers the lines. wc -l counts them.
Real rep (optional): on Linux, try tail -n 5 /var/log/dpkg.log, then less /etc/os-release and press q.
Bahasa Melayu
Kaunter ada buku pesanan, orders.log. Ia bertambah sepanjang hari. Anda cuma perlu pesanan terbaru. Apa anda buat?
cat orders.log cetak seluruh fail sekali gus. Bagus untuk fail pendek. Fail panjang pula laju terbang lepas mata anda.
Pilih alat yang betul untuk setiap kerja.
Tunjuk 3 pesanan terakhir sahaja: tail -n 3 orders.log.
-n 3 maksudnya “3 baris”.Apa yang head -n 1 orders.log cetak?
Perhati buku itu bertambah dengan tail -f orders.log. Ia pegang terminal. Hentikan dengan Ctrl+C.
-f maksudnya “follow”: terus perhati baris baru.Anda buka log panjang dengan less orders.log. Sudah cukup baca. Macam mana nak keluar?
Kini anda boleh baca atas fail, hujungnya, atau semuanya.
You finished this before. Practice is always welcome!
Official docs: cat (Debian 13 man page) · head (Debian 13 man page) · tail (Debian 13 man page) · less (Debian 13 man page)
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?