A system administrator is creating a script to monitor disk usage. The script must save a human-readable report of the /home directory's usage to a file named usage.log, overwriting any previous report. Any errors generated during the command's execution, such as permission errors, must be appended to a separate, persistent file named errors.log. Which command will accomplish this?
The correct command is du -h /home > usage.log 2>> errors.log. The > operator redirects standard output (the du report) to usage.log, overwriting the file if it already exists. The 2>> operator specifically redirects standard error (file descriptor 2) to errors.log, appending the new errors to the end of the file, which preserves a running log of all errors.
du -h /home > usage.log 2> errors.log is incorrect because the 2> operator will overwrite the errors.log file each time, failing the requirement to maintain a persistent error log.
du -h /home &> usage.log 2>> errors.log is incorrect. The &> operator redirects both standard output and standard error to usage.log. The subsequent redirection 2>> errors.log is processed after stderr has already been routed to usage.log, so it will not work as intended to separate the streams.
du -h /home 1>> usage.log 2>> errors.log is incorrect because 1>> (which is equivalent to >>) appends to the usage.log file, but the requirement is to overwrite it with the latest report.
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 'du' command do in Linux?
Open an interactive chat with Bash
What’s the difference between '>' and '>>' when redirecting output?