Quick Linux Tip #42:
Try: ./deploy.sh 2>&1 | tee -a deploy.log
Info: tee splits stdout to both terminal and file. 2>&1 redirects stderr into stdout first to capture error logs. -a appends output instead of overwriting.
Examples:
- $ ./script.sh 2>&1 | tee output.log # Overwrite log with output + errors
- $ make 2>&1 | tee build.log | grep -E 'error|warning' # Log all, filter display
- $ sudo apt upgrade 2>&1 | tee -a /var/log/upgrades.log # Append system upgrade log
Note: Without 2>&1, tee only captures standard output and misses error messages. Use tee -a when running repeated scripts to maintain a history.
Leave a Reply