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 输入.
难度 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.