Lesson 23 / 31
Pipes & xargs
Chain commands with pipes and turn output into arguments with xargs for flexible one-liners.
| 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
- Comments out the rest of the line
- Sends one command's output as the next command's input
- Creates a hard link
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.