Reading files
หน้านี้ต้องใช้เบราว์เซอร์ล่าสุด (รองรับ SharedArrayBuffer) กรุณาอัปเดต Chrome, Edge, Firefox หรือ Safari เป็นเวอร์ชันล่าสุด
English
Reading a file
catprints a file's contents straight to the screen:
cat poem.txt
- It is named after "concatenate" — it can also join several files together.

English
Just the start or end
- For a long file you often want only a peek:
headshows the first lines,tailshows the last lines.
head -n 2 poem.txt
tail -n 1 poem.txt
- The
-noption chooses how many lines.
English
Counting
wc(word count) measures a file. The most useful option is-lfor lines:
wc -l poem.txt
wc -wcounts words andwc -ccounts bytes (wc -mcounts characters; they differ only for letters such as é). Now try the tasks.
English
Common mistakes
catprints a whole file at once. On a real terminal,less poem.txtlets you scroll a long file; this practice terminal does not haveless.wc -lhere prints just the number. A real terminal adds the file name:4 poem.txt.- On a real terminal, Tab completes a long file name; this practice terminal has no Tab completion.
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
ใช้ cat to print the whole contents of poem.txt.
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
How many lines does the poem have? Use wc -l poem.txt to count them.
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Show only the first two lines of poem.txt. (No cat this time: print just those two lines.)
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Show only the สุดท้าย line of poem.txt.