# Disk Usage Analysis with `du` and `ncdu`: A Complete Guide

> Master disk usage analysis with du and ncdu. Learn to quickly view summaries and interactively explore your file system to find large files and directories.

- Repository: [Joshua Levy/the-art-of-command-line](https://github.com/jlevy/the-art-of-command-line)
- Tags: how-to-guide
- Published: 2026-02-24

---

**Use `du -hs *` for quick, human-readable disk usage summaries and `ncdu` for interactive exploration to identify large files and directories efficiently.**

The `jlevy/the-art-of-command-line` repository curates battle-tested command-line techniques for system administration and development. For **disk usage analysis**, the guide emphasizes two complementary approaches: the built-in `du` utility for rapid scripting and `ncdu` for visual navigation. Both tools appear in the main README as essential utilities for reclaiming storage space and understanding filesystem consumption.

## Quick Disk Inspection with `du`

According to the source code in [[`README.md`](https://github.com/jlevy/the-art-of-command-line/blob/main/README.md) at line 68](https://github.com/jlevy/the-art-of-command-line/blob/master/README.md#L68), `du` serves as the standard tool for generating a "quick summary of disk usage." The recommended invocation uses two critical flags:

- **`-h`** (human-readable): Displays sizes in K, M, G units instead of raw block counts.
- **`-s`** (summarize): Reports totals per argument without listing every subdirectory recursively.

### Basic Usage Examples

For a fast overview of top-level directory consumption:

```bash
du -hs *

```

Typical output shows relative weights at a glance:

```

1.4G   bin
56M    docs
3.2G   src
12K    README.md

```

To check the total size of the current directory tree (including all nested folders):

```bash
du -sh .

```

## Interactive Analysis with `ncdu`

When you need to drill down into directory hierarchies, the repository recommends `ncdu` at [[`README.md`](https://github.com/jlevy/the-art-of-command-line/blob/main/README.md) line 328](https://github.com/jlevy/the-art-of-command-line/blob/master/README.md#L328), noting it "saves time over the usual commands like `du -sh *`."

**`ncdu`** builds an ncurses-based interface that allows real-time navigation, sorting, and immediate deletion. Unlike `du`, which streams text output, `ncdu` calculates the entire tree once, then lets you explore interactively.

### Installation and Launch

Install the tool using your package manager:

```bash

# Debian/Ubuntu

sudo apt-get install ncdu

# macOS (Homebrew)

brew install ncdu

```

Launch an interactive session in the current directory:

```bash
ncdu .

```

Navigation uses arrow keys to traverse directories, **`d`** to delete selected files, and **`q`** to quit.

## Advanced `du` Patterns

For scripted analysis without interactivity, combine `du` with standard Unix utilities to surface the largest consumers.

### Sort by Size

To identify the top 20 largest files and directories:

```bash
du -ah . | sort -hr | head -n 20

```

Output lists paths descending by size:

```

1.2G ./node_modules
540M ./build
210M ./venv
...

```

### Excluding Specific Paths

Skip irrelevant filesystem branches like network mounts or Docker volumes:

```bash
du -h --max-depth=1 --exclude='./proc' --exclude='./sys' .

```

## Summary

- **`du -hs *`** provides immediate, human-readable summaries of current directory entries according to the [project README](https://github.com/jlevy/the-art-of-command-line/blob/master/README.md).
- **`du -ah . | sort -hr`** surfaces the largest files programmatically for automated reporting.
- **`ncdu`** delivers an interactive curses interface for visual exploration and on-the-spot cleanup, recommended for complex investigations.
- Both tools are documented across [language-specific READMEs](https://github.com/jlevy/the-art-of-command-line/blob/master/README-es.md) (e.g., [`README-es.md`](https://github.com/jlevy/the-art-of-command-line/blob/main/README-es.md)) for international users.

## Frequently Asked Questions

### What is the difference between `du` and `ncdu`?

`du` is a standard Unix utility that outputs text-based disk usage reports suitable for scripting and piping to other commands. `ncdu` is a third-party tool that provides an interactive, navigable interface built on ncurses, allowing you to browse directories, sort by size dynamically, and delete files immediately without leaving the terminal.

### How do I sort `du` output by size?

Pipe the output to `sort` with the `-h` flag for human-readable numeric sorting. The complete command is `du -ah . | sort -hr | head -n 20`, which lists all files and directories sorted from largest to smallest, limiting results to the top 20 entries.

### Is `ncdu` available on macOS?

Yes. Install it via Homebrew using `brew install ncdu`. It functions identically to the Linux version, providing the same keyboard-driven interface for analyzing APFS or HFS+ volumes.

### How can I see the total size of the current directory only?

Run `du -sh .`. The `-s` flag summarizes the entire directory tree into a single figure, while `-h` presents the result in human-readable units (e.g., 4.9G).