Beginner Topic 13 of 50 DevOps & Tooling
Pipes and Redirection
Connecting program outputs and inputs in shells.
How it works
Every process starts with three streams: standard input (0), standard output (1) and standard error (2). The pipe operator, a vertical bar, connects the output of one command to the input of the next, so listing processes, filtering for nginx and counting lines with wc -l can be done in one line. Redirection sends streams to files: > overwrites, >> appends, < reads input, 2> captures errors and 2>&1 merges them. Here-documents supply multi-line input, tee writes to a file and the screen together, and /dev/null discards output. Pipelines run their stages concurrently, streaming data between them.
Where it is used
Administrators and developers chain small tools to filter logs, transform data, build reports and capture command output for later analysis.
Common pitfall
Redirecting to the file you are reading truncates it before use, and forgetting stderr hides failures. By default a pipeline's status is the last command's, so enable pipefail to catch earlier errors.
Where it fits in the course
Pipes and Redirection is topic 13 of 50 in DevOps & Tooling, rated Beginner. It follows Shell Scripting. The next topic is grep, sed and awk.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the DevOps & Tooling quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the DevOps & Tooling quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Pipes and Redirection?
Where do people use Pipes and Redirection?
What is the most common mistake with Pipes and Redirection?
What should I learn before this topic?
How can I practice it?
Is Pipes and Redirection hard to learn?
How long does it take to learn Pipes and Redirection?
Which topics are related to Pipes and Redirection?
What should I study after Pipes and Redirection?
Related topics
- Shell Scripting (DevOps & Tooling)
- grep, sed and awk (DevOps & Tooling)
- Git Internals (DevOps & Tooling)
- Cron Jobs (DevOps & Tooling)
- Pipes and Signals (Operating Systems)