Pipes — joining commands · Tuyaux — joindre des commandes
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.
L'idée clé : les tuyaux (pipes)
- C'est ce qui rend le shell puissant. Un tuyau
|envoie directement la sortie d'une commande vers la suivante :
cat fruits.txt | sort
catproduit les lignes ;sortles reçoit et les classe. Aucun fichier intermédiaire.
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.
Construire une chaîne
- Vous pouvez en joindre autant que vous voulez, comme une chaîne de montage :
cat fruits.txt | sort | uniq
sortclasse les lignes, puisuniqsupprime les doublons adjacents — ainsi vous obtenez chaque fruit une seule fois.
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.
Petits outils, grands résultats
- Chaque commande fait une chose bien. Les tuyaux permettent de les combiner pour répondre à de vraies questions :
cat fruits.txt | sort | uniq | wc -l
- "Combien y a-t-il de fruits différents ?" — triez, déduplicuez, puis comptez. C'est la façon Unix.
Common mistakes
|sends one command's output into the next.- Order matters:
sort | uniq, not the other way round.
Erreurs courantes
|envoie la sortie d'une commande vers la suivante.- L'ordre compte :
sort | uniq, pas l'inverse.
Pipes join commands · Les tuyaux joignent des commandes
A pipe feeds one command's output · production into the next's input · entrée. · Un tuyau alimente la sortie d'une commande en entrée de la suivante.
Send the output of cat fruits.txt into · dans wc -l with a pipe |, to count the lines. · Envoyez la sortie de cat fruits.txt vers wc -l avec un tuyau |, pour compter les lignes.
List each fruit once, in order. Pipe sort into · dans uniq: cat fruits.txt | sort | uniq. · Listez chaque fruit une seule fois, dans l'ordre. Tuyautez sort vers uniq : cat fruits.txt | sort | uniq.