Wik-IT Monitoring and Performance Disk Usage Analysis with df, du, and ncdu
Monitoring and Performance

Disk Usage Analysis with df, du, and ncdu

Tutorial Overview

Learn to analyze and manage disk space usage using df, du, and ncdu on Debian-based systems. These tools help identify storage usage trends and allow efficient disk space management.

Prerequisites

  • Root or sudo access.

Steps

Step 1: Check Disk Space Usage with df

1. Run df to view available and used disk space:

df -h
  • The -h option displays output in a human-readable format (e.g., MB, GB).
  • Important columns:
    • Filesystem: The name of the disk or partition.
    • Size: Total size of the filesystem.
    • Used: Space currently in use.
    • Avail: Available space.
    • Use%: Percentage of space used.

2. Focus on Specific Filesystems:

  • To display only specific filesystems, use:
df -hT /path/to/mountpoint

Step 2: Find Disk Usage by Directory with du

1. Use du to show the size of a specific directory:

sudo du -sh /path/to/directory
  • The -s option gives a summary, and -h makes the output human-readable.

2. Display Sizes of All Subdirectories:

  • To list all subdirectories within a directory, use:
sudo du -h --max-depth=1 /path/to/directory
  • Adjust –max-depth to control the level of detail.

3. Identify Large Files Recursively:

  • Find large files by sorting du output:
sudo du -ah /path/to/directory | sort -rh | head -n 10

Step 3: Use ncdu for a Visual Disk Usage Summary

1. Install ncdu:

sudo apt install ncdu -y

2. Run ncdu in the desired directory:

sudo ncdu /path/to/directory
  • ncdu provides an interactive display of directory sizes, making it easy to identify large files and folders.

3. Navigating ncdu:

  • Use the arrow keys to navigate.
  • Press Enter to explore a directory.
  • Press d to delete a selected file or directory.
  • Press q to quit.
Exit mobile version