Przejdลบ do treล›ci

๐Ÿ”— Pipelines

Pipes (|) connect the output of one command to the input of another, forming powerful chains of operations.

๐Ÿ”— How Pipes Work

Syntax:

1
command1 | command2 | command3

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
$ ps aux | grep nginx

Finds all processes matching "nginx".


๐Ÿงช Real-World Pipeline Examples

Count number of files:

1
$ ls | wc -l

Sort unique IP addresses from logs:

1
$ awk '{print $1}' access.log | sort | uniq

Filter JSON logs by field value:

1
$ jq -r '.timestamp' logs.json | sort

Process CSV columns:

1
$ cut -d',' -f2 data.csv | sort | uniq -c


๐Ÿง  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