Storage usage overview: Which command summarizes disk usage for files and directories (for example, showing total space consumed by each subdirectory)?

Difficulty: Easy

Correct Answer: du

Explanation:


Introduction / Context:
Understanding how storage is consumed on a server or workstation helps with capacity planning and cleanup. The du utility reports the amount of disk space used by files and directories, optionally aggregating totals at each directory level.



Given Data / Assumptions:

  • A POSIX system with standard userland tools is available.
  • You want a summary per directory or a grand total.
  • Human-readable sizes are preferred for quick interpretation.


Concept / Approach:

du traverses directories and sums allocated blocks. Useful flags include -h for human-readable units, -s for summary (do not descend), and -x to stay on one filesystem. Pair du with sort -h to identify the largest disk consumers quickly.



Step-by-Step Solution:

Show per-directory usage: du -h .Summarize only the current directory: du -sh .Find top consumers: du -h --max-depth=1 | sort -hLimit to one filesystem: du -xh / | sort -h | tailAutomate cleanup decisions by reviewing the largest paths.


Verification / Alternative check:

Use df -h to verify overall filesystem free/used space. Compare du results before and after deleting large logs or caches to confirm reclaimed space. Note that sparse files and copy-on-write filesystems may complicate exact interpretations.



Why Other Options Are Wrong:

a: disk is not a standard UNIX command for usage summarization.

c: fdisk edits partition tables; it does not report per-directory usage.

d: chkdsk is a DOS/Windows filesystem checker, not a UNIX usage tool.

e: Not applicable because du is correct.



Common Pitfalls:

Running du on mount points with slow or remote filesystems, misinterpreting sizes when hard links or snapshots are present, and forgetting -x when you want to avoid descending into other mounted filesystems.



Final Answer:

du

More Questions from Linux

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion