A Linux administrator is running a diagnostic script named net_check.sh. The administrator needs to save the standard output of this script to a file named net_report.log, ensuring that any existing file with the same name is overwritten. The standard error messages should not be saved to the file but should remain visible on the terminal. Which of the following commands correctly accomplishes this task?
The correct command is bash net_check.sh > net_report.log. In Bash, standard output is represented by file descriptor 1, and standard error is file descriptor 2. The > operator redirects standard output to a file. If the file descriptor is not specified, > defaults to redirecting standard output (file descriptor 1). Therefore, > net_report.log is equivalent to 1> net_report.log. This command redirects only the standard output to net_report.log and overwrites the file if it already exists, leaving standard error to be displayed on the terminal. The command bash net_check.sh 2> net_report.log incorrectly redirects only standard error (file descriptor 2) to the file. The command bash net_check.sh &> net_report.log is a shorthand that redirects both standard output and standard error to the file. The command bash net_check.sh >> net_report.log incorrectly appends the standard output to the file instead of overwriting it.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the `>` operator in Bash do?
Open an interactive chat with Bash
What is the difference between `>` and `>>` in Bash?
Open an interactive chat with Bash
How can you redirect both standard output and standard error in Bash?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
System Management
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access