๐ Pipelines
Pipes (|) connect the output of one command to the input of another, forming powerful chains of operations.
๐ How Pipes Work
Syntax:
1 | |
Data flows left to right:
1. command1 writes to stdout
2. Pipe connects stdout of command1 to stdin of command2
3. And so on...
Example:
1 | |
Finds all processes matching "nginx".
๐งช Real-World Pipeline Examples
Count number of files:
1 | |
Sort unique IP addresses from logs:
1 | |
Filter JSON logs by field value:
1 | |
Process CSV columns:
1 | |
๐ง Behind the Scenes
Each stage runs in a subshell concurrently. The kernel handles buffering and synchronization automatically.
However: - Large outputs may cause temporary slowdowns. - Too many stages increase complexity and reduce readability.
Best practice: Keep pipelines short and focused.
๐งพ Summary
- Pipes chain commands together seamlessly.
- Each command receives input from previous one.
- Useful for filtering, transforming, aggregating data.
- Can become unwieldy if too long โ keep readable.
๐ Continue to: Variables and Environment