A system administrator is running a diagnostic script, diag.sh, which produces important status messages on both standard output and standard error. The administrator needs to view the combined output on the terminal in real-time and simultaneously append it to a log file named activity.log without overwriting the file's existing contents. Which of the following commands will accomplish this?
The correct command is sh diag.sh 2>&1 | tee -a activity.log. Here is a breakdown of the command:
sh diag.sh: Executes the script.
2>&1: This redirects the standard error file descriptor (2) to the same location as the standard output file descriptor (1).
|: The pipe operator sends the combined standard output and standard error of the preceding command as standard input to the next command.
tee -a activity.log: The tee command reads from standard input and writes to both standard output (the terminal) and the specified file. The -a option ensures that the output is appended to activity.log rather than overwriting it.
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.
What does '2>&1' mean in the command?
Open an interactive chat with Bash
What is the purpose of the 'tee' command?
Open an interactive chat with Bash
Why is the '-a' option necessary for 'tee' in this command?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
System Management
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access