How to redirect output to file in bash
Answered
50
How do I save command output to a file? Also how to redirect errors?
H
Asked by
hassan_ops
Bronze
•
565 rep
1 Answer
27
# Redirect stdout
command > output.txt
# Append instead of overwrite
command >> output.txt
# Redirect stderr
command 2> errors.txt
# Redirect both stdout and stderr
command > output.txt 2>&1
# Or modern syntax
command &> output.txt
# Redirect stderr to stdout
command 2>&1 | tee output.txt
P
Platinum
•
447 rep
Your Answer
You need to be logged in to answer questions.
Log In to Answer