50
How do I save command output to a file? Also how to redirect errors?
Loading...
Q&A · Answered
How do I save command output to a file? Also how to redirect errors?
Accepted answer
# 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.txtSay what you tried, not only what worked — the next person needs the reasoning. Code goes in a fenced block.