Lesson 22 / 29
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.
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.
find . -name "*.tmp" | xargs rmQuick check: What does the `|` operator do?
- Runs two commands in parallel
- 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.