Which redirection sends standard error to standard output so both streams share the same destination?

Prepare for the Red Hat Certified Systems Admin Exam EX200. Enhance your skills with interactive quizzes, flashcards, and detailed explanations. Ace your certification exam today!

Multiple Choice

Which redirection sends standard error to standard output so both streams share the same destination?

Explanation:
Duplicating file descriptors lets you funnel both outputs to one place. In shells, stdout is file descriptor 1 and stderr is file descriptor 2. By using 2>&1 you tell the shell to redirect stderr to the same destination as stdout, so both streams go to the same place. The typical pattern is to direct stdout first, then attach stderr to that same destination, e.g. command > log.txt 2>&1, which makes both stdout and stderr appear in log.txt. Other options behave differently: redirecting only stderr (2> File) sends errors to a file, not to stdout; redirecting stdout to stderr’s destination (1>&2) sends stdout to wherever stderr is going (often the terminal); and a shorthand like &> File redirects both streams to the file but isn't the explicit duplication of stdout for stderr in the same way.

Duplicating file descriptors lets you funnel both outputs to one place. In shells, stdout is file descriptor 1 and stderr is file descriptor 2. By using 2>&1 you tell the shell to redirect stderr to the same destination as stdout, so both streams go to the same place. The typical pattern is to direct stdout first, then attach stderr to that same destination, e.g. command > log.txt 2>&1, which makes both stdout and stderr appear in log.txt.

Other options behave differently: redirecting only stderr (2> File) sends errors to a file, not to stdout; redirecting stdout to stderr’s destination (1>&2) sends stdout to wherever stderr is going (often the terminal); and a shorthand like &> File redirects both streams to the file but isn't the explicit duplication of stdout for stderr in the same way.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy