Bash — Redirection
Standard streams
# stdout (1)
echo "Hello" > file.txt
echo "Hello" >> file.txt
# stderr (2)
command 2> error.txt
# stdin (0)
command < input.txt
Redirect both
command > output.txt 2>&1
command &> output.txt
Here document
cat << EOF
Line 1
Line 2
EOF
/dev/null
command > /dev/null 2>&1
Mini Practice
- Redirect stdout
- Redirect stderr
- Use here document
- Suppress output
Up Next
Continue with Text Processing - awk, sed, grep.
Related Topics
Frequently Asked Questions about Redirection
What is Redirection in Bash?
Redirection is a fundamental concept in Bash. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Redirection?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Redirection.
Why is Redirection important in Bash?
Redirection is essential for Bash development. Understanding this concept will help you write better code and solve real-world problems more effectively.