CompTIA Linux+ Powered by LPI (LX0-103) — Question 9
Which of the following shell redirections will write standard output and standard error output to a file named filename?
Answer options
- A. 2>&1 >filename
- B. >filename 2>&1
- C. 1>&2>filename
- D. >>filename
- E. 1&2>filename
Correct answer: B
Explanation
The correct answer, B, uses '>filename' to redirect standard output to the file first and then '2>&1' to redirect standard error to the same destination. Option A redirects standard error to standard output first but does not redirect standard output to the file correctly. Option C is incorrectly formatted and does not achieve the desired output redirection. Option D only appends standard output to the file, and option E is a syntax error.