Linux › Module 5 › Lesson 1
Pipes and Redirection (|, >, >>)
Chain commands with pipes and save output using redirection
Opening
One command is good. A chain is power.
Linux shines when you combine small tools. A pipe (|) sends one command's output into the next. Redirection (>, >>) saves results to a file. This is how analysts filter millions of log lines in seconds.
1. The Pipe: |
Read left to right—output flows through: ls -l | less — long list, scroll page by page cat access.log | wc -l — count lines in a file history | tail -5 — last five commands you ran
2. Redirect Output: > and >>
> creates or overwrites a file: echo "scan started" > status.txt >> appends without erasing: date >> status.txt echo "done" >> status.txt
3. stderr: 2>
Programs send normal output to stdout (1) and errors to stderr (2). command 2> errors.txt — save errors only command &> all.txt — save both streams
Blue team example
cat /var/log/auth.log | grep "Failed password" | wc -l Counts failed SSH logins—fast breach signal.
Knowledge Check
What does the pipe symbol | do?
Multiple choice
Knowledge Check
Which operator appends to a file without overwriting?
Multiple choice
Knowledge Check
True or False: You can chain more than two commands with pipes.
True or False