Home How To How to Use ncdu to Analyze Disk Usage

How to Use ncdu to Analyze Disk Usage

Last updated on Jan 23, 2025

This guide explains how to use ncdu (NCurses Disk Usage) on Ubuntu to browse, analyze, and manage disk space. With ncdu, you can easily identify large files and directories, navigate through your filesystem, delete unnecessary files, and free up disk space.


Step 1: Launch ncdu

  1. Open your terminal.

  2. Run the following command to start ncdu in the current directory:

    ncdu
    

    ncdu will scan the directory and its subdirectories, displaying a list of files and folders sorted by size.

  3. If you want to scan a specific directory, use:

    ncdu /path/to/directory
    

    Replace /path/to/directory with the directory you want to analyze.


Step 2: Understanding the Interface

After ncdu finishes scanning, you will see:

  • A list of files and directories, sorted by size (largest at the top).

  • The total size of the scanned directory displayed at the top of the interface.

  • File and directory sizes are displayed on the left.


Step 3: Navigating in ncdu

Use the following keys to navigate within ncdu:

  • Up/Down Arrow Keys: Move up or down through the list.

  • Enter: Open (navigate into) a directory or view the contents of a file.

  • Left Arrow: Go back to the parent directory.

  • Right Arrow: Open a directory (same as Enter).


Step 4: Deleting Files or Directories

To delete unwanted files or directories:

  1. Navigate to the file or directory you want to delete using the arrow keys.

  2. Press d (delete) on your keyboard.

  3. Confirm the deletion when prompted.

    Warning: Be careful when deleting files, as this action is irreversible.


Step 5: Quit ncdu

To exit ncdu, press q on your keyboard.


Example Commands

  • Scan the root directory (requires sudo):

    sudo ncdu /
    
  • Analyze a specific directory (e.g., /var):

    ncdu /var
    

Conclusion

ncdu is a powerful and user-friendly tool for managing disk space on Ubuntu. By navigating through directories and identifying large files, you can efficiently free up space. Always double-check files before deletion to avoid accidentally removing important data.