nerdexam
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 >filename is incorrect because 2>&1 redirects stderr to where stdout currently points (the terminal), and then >filename redirects only stdout to 'filename', leaving stderr going to the terminal.
  • C. 1>&2>filename is incorrect syntax; 1>&2 would redirect stdout to stderr, and then >filename would attempt to redirect stdout (which is now linked to stderr) to the file, but the original stderr would still go to the terminal.
  • D. >>filename redirects only standard output to 'filename' in append mode, it does not redirect standard error.
  • E. 1&2>filename is 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.

Full LFCS PracticeBrowse All LFCS Questions