A system administrator is analyzing disk space usage in the /var/log directory, which has many subdirectories. The goal is to see the individual disk usage for each immediate subdirectory within /var/log in a human-readable format, without listing the contents of deeper, nested directories. Which of the following commands will achieve this?
The correct command is du -h --max-depth=1 /var/log. The du command is used to estimate file space usage. The -h option presents the sizes in a human-readable format (e.g., K for kilobytes, M for megabytes). The --max-depth=1 option is crucial here; it restricts the output to a depth of one directory level below the target (/var/log), thus showing the total size of each immediate subdirectory without descending further.
du -sh /var/log/* is incorrect because it relies on shell globbing (*) to list the contents of /var/log. This approach will not show the size of hidden directories (those starting with a dot) and is a less direct way to control directory depth.
df -h /var/log is incorrect. The df (disk free) command reports the total disk space usage for the entire filesystem on which /var/log resides, not the specific usage of the /var/log directory and its subdirectories.
ls -lh /var/log is incorrect. The ls command lists directory contents. For directories, the size it displays is that of the directory file itself (the metadata), not the total size of all the files and subdirectories it contains.
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 `--max-depth` option do in the `du` command?
Open an interactive chat with Bash
How is the `du` command different from the `df` command?
Open an interactive chat with Bash
Why is `ls -lh /var/log` not suitable for checking subdirectory sizes?
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...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .