Pipes — joining commands
หน้านี้ต้องใช้เบราว์เซอร์ล่าสุด (รองรับ SharedArrayBuffer) กรุณาอัปเดต Chrome, Edge, Firefox หรือ Safari เป็นเวอร์ชันล่าสุด
English
The big idea: pipes
- This is what makes the shell powerful. A pipe
|sends one command's output straight into the next command:
cat fruits.txt | sort
catproduces the lines;sortreceives them and puts them in order. No file in between.

English
Build a chain
- You can join as many as you like, like an assembly line:
cat fruits.txt | sort | uniq
sortorders the lines, thenuniqremoves neighbouring duplicates — so you get each fruit once.
English
Small tools, big results
- Each command does one job well. Pipes let you combine them to answer real questions:
cat fruits.txt | sort | uniq | wc -l
- "How many different fruits are there?" — sort, dedupe, then count. That is the Unix way.
English
Common mistakes
|sends one command's output into the next.- Order matters:
sort | uniq, not the other way round.
สำรวจ
Pipes join commands
A pipe feeds one command's ผลผลิต into the next's input (อินพุต).
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Send the output of cat fruits.txt เข้าใน wc -l with a pipe |, to count the lines.
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
List each fruit once, in order. Pipe sort เข้าใน uniq: cat fruits.txt | sort | uniq.
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
How many lines of fruits.txt say apple? Pipe the matching lines from grep เข้าใน wc -l.