Question 330
A Linux administrator faces this situation: A script needs to record both standard output and error output in a single file for one command. Which action best resolves the specific issue while preserving correct system behavior?
Explanation
Correct Answer
Use command > combined.log 2>&1 with the intended shell redirection order. This corrects the case-specific failure. First verify: Inspect the redirection ordering and decide whether both descriptors should share the file. Then demonstrate success: The resulting file contains both normal lines and error messages from the command.
Incorrect Answers
Pipe the command output into tee output.log so the stream reaches both the terminal and file. That would matter when an operator needs to view command output on screen and retain the same stream in a file. The relevant distinction in this case is: Use command > combined.log 2>&1 with the intended shell redirection order.
Redirect only stdout with command > report.txt and leave stderr separate. That would matter when a command writes reports to standard output and warnings to standard error but only reports should enter a data file. It does not address this case's requirement: A script needs to record both standard output and error output in a single file for one command.
Use command >> execution.log rather than overwriting redirection. That would matter when a maintenance script should append standard output to a cumulative log while retaining earlier runs. That separate mechanism does not verify the needed Linux administration outcome in this case.