# Pipes & xargs — Linux

Source: https://www.geekswithgeeks.com/en/linux/linux-pipes-xargs

> Chain commands, and turn output into arguments.

## | chains commands

A pipe feeds one command's stdout as the next command's stdin, so small tools combine into a pipeline.

```bash
ps aux | grep nginx | wc -l
```

Output:

```
2
```

## xargs — turn lines into arguments

`xargs` takes lines from stdin and passes them as arguments to another command — useful when a command doesn't read stdin itself.

```bash
find . -name "*.tmp" | xargs rm
```

**Quiz:** What does the `|` operator do?

- [ ] Runs two commands in parallel
- [x] Sends one command's output as the next command's input
- [ ] Comments out the rest of the line

*Answer:* Sends one command's output as the next command's input. That's exactly what a pipe does — connect stdout to the next command's stdin.
