A system administrator wants to generate a report of disk usage by each user in the home directory and store the output to a file called disk_report.txt, overwriting any existing data in the file. Which command should they use to accomplish this task?
The correct answer is 'du -h /home/* > disk_report.txt' because the '>' operator will redirect the output of the 'du' command to 'disk_report.txt', overwriting its contents every time the command is run, thus only saving the latest disk usage report in the file.
The 'du -h /home/* >> disk_report.txt' is incorrect because using the '>>' operator would append to the file rather than overwriting it, leading to accumulation of data over time rather than maintaining a single report.
The 'du -h /home/* < disk_report.txt' is incorrect because the '<' operator is used for input redirection, which is not what is needed when intending to write to a file.
Lastly, 'du -h /home/* &> disk_report.txt' is incorrect as '&>' redirects both standard output and standard error to a file, which could include error messages in the report unnecessarily.
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?
Open an interactive chat with Bash
What do the operators '>' and '>>' do in the context of command line?
Open an interactive chat with Bash
What is the significance of the home directory in Linux?