Learn the correct shell redirection syntax to write both standard output and standard error to a file in the Linux Foundation Certified System Administrator (LFCS) exam. Understand the order of redirections and how to effectively combine them for desired results.
Table of Contents
Question
Which of the following shell redirections will write standard output and standard error output to a file named filename?
A. 2>&1 >filename
B. >filename 2>&1
C. 1>&2>filename
D. >>filename
E. 1&2>filename
Answer
B. >filename 2>&1
Explanation
The redirection >filename sends the standard output to the file “filename”, overwriting its contents. The redirection 2>&1 redirects the standard error (file descriptor 2) to the same destination as the standard output (file descriptor 1). By placing >filename before 2>&1, the standard output is first redirected to “filename”, and then the standard error is redirected to the same destination as the standard output, effectively writing both standard output and standard error to “filename”.
Linux Foundation Certified System Administrator LFCS certification exam practice question and answer (Q&A) dump with detail explanation and reference available free, helpful to pass the Linux Foundation Certified System Administrator LFCS exam and earn Linux Foundation Certified System Administrator LFCS certification.