Which command in Linux is used to estimate and display the disk space usage of…

2023

Which command in Linux is used to estimate and display the disk space usage of files and directories?

  1. A.

    ls

  2. B.

    df

  3. C.

    du

  4. D.

    top

  5. E.

    mkdir

Attempted by 3 students.

Show answer & explanation

Correct answer: C

Concept

Linux disk-related commands split into two distinct jobs. One job reports usage at the level of individual files and directory trees (how much space a given set of files occupies). The other job reports usage at the level of whole mounted filesystems (how much total space and free space a partition has). The first is what “estimate and display the disk space usage of files and directories” asks for.

Application

The du command (short for “disk usage”) walks a file or directory tree and reports the space occupied by each item, summarising recursively. Running du -sh /path prints a single human-readable total for that path, which is exactly the per-file/per-directory estimate the question describes.

Contrast

  • df reports free and used space for whole mounted filesystems, not for individual files or directories.

  • ls lists directory contents (names, permissions, sizes of entries) but does not total or estimate tree usage.

  • top is a live process/CPU/memory monitor and reports nothing about disk space.

  • mkdir creates a new directory and performs no measurement at all.

So the command that estimates and displays disk-space usage of files and directories is du.

Explore the full course: Niacl Ao It Specialist