Linux_FoundationLinux_Foundation
LFCS · Question #808
LFCS Question #808: Real Exam Question with Answer & Explanation
The correct answer is B: >filename 2>&1. This question assesses the correct syntax for redirecting both standard output (stdout) and standard error (stderr) to the same file in a Bash shell.
Submitted by paula_co· Apr 18, 2026Essential Commands
Question
Which of the following shell redirections will write standard output and standard error output to a file named filename?
Options
- A2>&1 >filename
- B>filename 2>&1
- C1>&2>filename
- D>>filename
- E1&2>filename
Explanation
This question assesses the correct syntax for redirecting both standard output (stdout) and standard error (stderr) to the same file in a Bash shell.
Common mistakes.
- A.
2>&1 >filenameis incorrect because2>&1redirects stderr to where stdout currently points (the terminal), and then>filenameredirects only stdout to 'filename', leaving stderr going to the terminal. - C.
1>&2>filenameis incorrect syntax;1>&2would redirect stdout to stderr, and then>filenamewould attempt to redirect stdout (which is now linked to stderr) to the file, but the original stderr would still go to the terminal. - D.
>>filenameredirects only standard output to 'filename' in append mode, it does not redirect standard error. - E.
1&2>filenameis incorrect syntax and does not achieve the desired redirection for both streams.
Concept tested. Bash stdout and stderr redirection
Reference. https://www.gnu.org/software/bash/manual/bash.html#Redirections
Topics
#Shell Redirection#Standard Output#Standard Error#File Descriptors
Community Discussion
No community discussion yet for this question.