World map

 

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 are hereyou@kedai:~/kedai/counter$

Folder ~/kedai/counter

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

Services

  • cronrunningstarts at boot
  • sshrunningstarts at boot
  • nginxrunningstarts 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 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

        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 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

        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.