Quick Linux Tip #66:
Question: How do I save errors and normal output to different files?
Try: ./deploy.sh > success.log 2> errors.log
Info: > redirects stdout (file descriptor 1), while 2> redirects stderr (file descriptor 2). Separating the two streams keeps normal output and error messages in different files for easier troubleshooting.
Examples:
- $
./script > out.log 2> err.log# Separate standard output and errors - $
./script &> combined.log# Redirect both streams to one file (Bash/Zsh) - $
./script > out.log 2>&1# Send stderr to the same file as stdout
Note: Redirection order matters: > file 2>&1 sends both streams to the file, while 2>&1 > file sends stderr to the terminal and only stdout to the file. Redirect to /dev/null when you want to discard output completely.
Leave a Reply