Disk Usage and Space Management CLI Tools Quiz Quiz

Assess your understanding of disk usage analysis and space management using command-line tools. This quiz covers essential commands, output interpretation, and practical scenarios for maintaining disk health on systems via CLI.

  1. Identifying Large Directories

    Which command would you use to quickly display the sizes of directories in the current location, sorted from largest to smallest, to investigate space usage issues?

    1. du -sh * | sort -hr
    2. df -lh
    3. ls -ltr
    4. diskstat -sv

    Explanation: The correct answer is 'du -sh * | sort -hr', which combines disk usage summary with sorting in human-readable form, making it easy to see which directories consume the most space. 'df -lh' shows file system-level usage, not individual directories. 'ls -ltr' lists files by modification time, unrelated to size sorting. 'diskstat -sv' is not a standard disk usage command.

  2. Understanding the 'df' Command

    If you want to check total, used, and available disk space for all mounted filesystems in a human-readable format, which option for the 'df' command should you use?

    1. df -h
    2. df -a
    3. df --sum
    4. df -s

    Explanation: 'df -h' displays disk space information in human-readable form such as GB or MB, which is ideal for reviewing storage. 'df -a' includes dummy file systems and is usually unnecessary. 'df --sum' is not a valid option, and 'df -s' summarizes disk usage per argument, rather than listing all file systems.

  3. Freeing Up Space

    After noticing your home directory is nearly full, which command can you use to interactively remove unnecessary files and free up space using a CLI utility?

    1. ncdu ~
    2. dd if=/dev/zero of=~/file
    3. touch cleanup
    4. mkdir deleted_files

    Explanation: 'ncdu ~' launches an interactive disk usage analyzer in your home directory, allowing you to view and delete files safely. 'dd if=/dev/zero...' actually creates a file and adds data, using more space. 'touch cleanup' just creates an empty file. Creating a directory with 'mkdir deleted_files' does not remove any existing data.

  4. Investigating Space-Hungry Log Files

    If a system is running low on disk space and you suspect large log files in /var/log, which single command helps you list all files in that directory larger than 100 megabytes?

    1. find /var/log -type f -size +100M
    2. ls -lhS /var/log | grep 100M
    3. du -h /var/log | sort -n | grep 100M
    4. grep 100M /var/log/*

    Explanation: 'find /var/log -type f -size +100M' finds files over 100 MB inside /var/log. 'ls -lhS' lists by size but doesn't filter specifically by 100 MB. The 'du' and 'sort' pipeline shows directory sizes, not individual files, and 'grep 100M /var/log/*' looks for the text '100M' in files, not their size.

  5. Comparing Usage Across Filesystems

    When comparing disk usage across multiple mounted filesystems, which 'df' output column should you primarily consult to see available free space?

    1. Available
    2. Used
    3. 1K-blocks
    4. Filesystem

    Explanation: The 'Available' column shows how much free space remains for new data storage on each filesystem, which is essential for space management. The 'Used' column displays only what's currently in use. '1K-blocks' or similar columns show the total capacity. 'Filesystem' identifies the mount point, not its space specifics.