A systems administrator is executing a deployment script, deploy.sh, that generates output on both stdout and stderr. The administrator needs to monitor the script's progress in real-time on the terminal while simultaneously saving all output to a file named deploy.log, overwriting the file if it already exists. Which of the following commands should the administrator use?
The correct command is ./deploy.sh 2>&1 | tee deploy.log. Here's a breakdown of why: 2>&1 redirects the standard error (file descriptor 2) to the same location as standard output (file descriptor 1). The pipe | then takes this combined stream and sends it to the tee command's standard input. tee then does two things: it prints the stream to its standard output (the terminal) and also writes it to the specified file, deploy.log. The option ./deploy.sh > deploy.log 2>&1 redirects all output to the file, but nothing is displayed on the terminal. The option ./deploy.sh | tee deploy.log only pipes stdout to tee; stderr is not captured and will be displayed on the terminal but not written to the log file. The option ./deploy.sh | tee -a deploy.log also fails to capture stderr and incorrectly appends to the log file instead of overwriting it, as specified by the scenario.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
How does the 'tee' command work in Linux?
Open an interactive chat with Bash
What is the difference between the '>' and '>>' operators in Linux?
Open an interactive chat with Bash
What is the role of the pipe ('|') operator in Linux?