An administrator wants to monitor disk usage by individual users on a shared system and has decided to utilize the output from the 'du' command. The command 'du -s /home/*' produces a list of directories and their sizes within the /home directory, which is then redirected to 'awk' for further processing. The administrator is interested in directories that consume more than 1GB of disk space. Which 'awk' command should the administrator use to extract and print the usernames (the directory names within /home) and their corresponding disk space usage in gigabytes, but only for those users utilizing more than 1GB?
The correct 'awk' command filters the output of 'du' by dividing the first column (size in kilobytes) by 1048576 to convert it to gigabytes and prints the size along with the username, which is inferred from the directory name after the last slash in the second column. The 'substr($2,7)' function is utilized to remove '/home/' (the first 6 characters), leaving the username. Only records with a size greater than 1GB are output.
As for the incorrect answers:
The second answer overlooks the requirement to convert kilobytes to gigabytes before comparing to 1GB.
The third answer uses incorrect syntax, merging the 'if' construct improperly.
The fourth answer is incorrect because it prints all records, and it attempts to use a field '$3' that does not exist in the 'du' output.
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 is the purpose of 'awk' in this command?
Open an interactive chat with Bash
Why is 1048576 used for the comparison in the 'awk' command?