Pipes — joining commands · Pipes — nối các lệnh
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · Trang này cần trình duyệt gần đây (hỗ trợ SharedArrayBuffer). Vui lòng cập nhật Chrome, Edge, Firefox hoặc Safari lên phiên bản mới nhất.
English
The big idea: pipes
- This is what makes the shell powerful. A pipe
|sends one command's output straight into the next command:
catproduces the lines;sortreceives them and puts them in order. No file in between.
Tiếng Việt
Ý tưởng cốt lõi: đường ống (pipes)
- Đây chính là thứ khiến shell trở nên mạnh mẽ. Một đường ống
|gửi trực tiếp kết quả của một lệnh vào lệnh tiếp theo:
cat fruits.txt | sort
catsinh ra các dòng;sortnhận chúng và sắp xếp theo thứ tự. Không có file trung gian nào.
English
Build a chain
- You can join as many as you like, like an assembly line:
sortorders the lines, thenuniqremoves neighbouring duplicates — so you get each fruit once.
Tiếng Việt
Xây dựng chuỗi
- Bạn có thể nối nhiều lệnh lại với nhau tùy thích, giống như một dây chuyền sản xuất:
cat fruits.txt | sort | uniq
sortsắp xếp các dòng theo thứ tự, sau đóuniqloại bỏ các trùng lặp liền kề — để bạn chỉ thấy mỗi loại trái cây một lần.
English
Small tools, big results
- Each command does one job well. Pipes let you combine them to answer real questions:
- "How many different fruits are there?" — sort, dedupe, then count. That is the Unix way.
Tiếng Việt
Công cụ nhỏ, kết quả lớn
- Mỗi lệnh thực hiện một công việc tốt. Đường ống cho phép bạn kết hợp chúng để trả lời các câu hỏi thực tế:
cat fruits.txt | sort | uniq | wc -l
- "Có bao nhiêu loại trái cây khác nhau?" — sắp xếp, loại bỏ trùng lặp, rồi đếm. Đó là cách làm chuẩn của Unix.
English
Common mistakes
|sends one command's output into the next.- Order matters:
sort | uniq, not the other way round.
Tiếng Việt
Lỗi thường gặp
|gửi kết quả của một lệnh vào lệnh tiếp theo.- Thứ tự rất quan trọng: hãy dùng
sort | uniq, không phải ngược lại.
Explore · Khám phá
Pipes join commands · Pipes nối các lệnh
A pipe feeds one command's output into the next's input. · Một pipe truyền đầu ra của lệnh này vào đầu vào của lệnh kế tiếp.
Send the output of cat fruits.txt into wc -l with a pipe |, to count the lines. · Gửi đầu ra của cat fruits.txt vào wc -l bằng pipe |, để đếm số dòng.
List each fruit once, in order. Pipe sort into uniq: cat fruits.txt | sort | uniq. · Liệt kê mỗi loại trái cây một lần, theo thứ tự. Pipe sort vào uniq: cat fruits.txt | sort | uniq.