Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

gdu

> 开发工具
Open source

Fast disk usage analyzer with console interface written in Go

5.9K stars0 likes1 views
WebsiteGitHub

About

Fast disk usage analyzer with console interface written in Go

go DiskUsage()

Pretty fast disk usage analyzer written in Go.

Gdu is intended primarily for SSD disks where it can fully utilize parallel processing. However HDDs work as well, but the performance gain is not so huge.

Installation

Head for the releases page and download the binary for your system.

Using curl:

bash
curl -L https://github.com/dundee/gdu/releases/latest/download/gdu_linux_amd64.tgz | tar xz
chmod +x gdu_linux_amd64
mv gdu_linux_amd64 /usr/bin/gdu

See the installation page for other ways how to install Gdu to your system.

Or you can use Gdu directly via Docker:

bash
docker run --rm --init --interactive --tty --privileged --volume /:/mnt/root ghcr.io/dundee/gdu /mnt/root

Usage

…

Examples

gdu                                   # analyze current dir
gdu -a                                # show apparent size instead of disk usage
gdu --no-delete                       # prevent write operations
gdu --no-view-file                    # prevent viewing file contents
gdu --trash-command 'trash-put --trash-dir ~/mytrash'   # use own trash command for the D key
gdu --trash-command 'mv -f "$1" ~/mytrash/'             # trash by moving items with mv
gdu <some_dir_to_analyze>             # analyze given dir
gdu dir_a dir_b dir_c                 # analyze several dirs at once
gdu -d                                # show all mounted disks
gdu -l ./gdu.log <some_dir>           # write errors to log file
gdu -i /sys,/proc /                   # ignore some paths
gdu -I '.*[abc]+'                     # ignore paths by regular pattern
gdu -X ignore_file /                  # ignore paths by regular patterns from file
gdu -c /                              # use only white/gray/black colors

gdu -n /                              # only print stats, do not start interactive mode
gdu --interactive / | tee out.txt     # force interactive mode even when stdout is piped
gdu -p /                              # do not show progress, useful when using its output in a script
gdu -ps /some/dir                     # show only total usage for given dir
gdu -t 10 /                           # show top 10 largest files
gdu --reverse-sort -n /               # show files sorted from smallest to largest in non-interactive mode
gdu / > file                          # write stats to file, do not start interactive mode

gdu -o- / | gzip -c >report.json.gz   # write all info to JSON file for later analysis
zcat report.json.gz | gdu -f-         # read analysis from file

gdu --db=tmp.badger /                 # use persistent key-value storage for saving analysis data
gdu --db=tmp.db /                     # use persistent SQLite storage for saving analysis data
gdu -r /                              # read saved analysis data from persistent key-value storage

gdu --web /                           # analyze and browse the results in a web browser
gdu --web --web-listen localhost:8080 /   # serve the web UI on a fixed address
gdu --web --web-open=false /          # print the URL but do not open a browser

Scanning multiple directories

More than one directory can be given on the command line, which is useful when only a subset of a large directory is of interest:

gdu ~/projects/alpha ~/projects/beta ~/projects/gamma

The directories are scanned one after another and presented together under a virtual top level directory named (multiple), so they can be compared and sorted like ordinary siblings. They are listed by their absolute path, so directories that share a base name stay distinguishable. Each of them keeps its real path, so rescanning, deletion and opening a shell work as usual once you navigate into one of them.

The virtual top level directory itself has no counterpart on disk, so operations that need a real path are unavailable while it is shown: --change-cwd, spawning a shell, browsing to the parent directory (--browse-parent-dirs) and exporting to JSON. Rescanning it rescans every directory below it.

Directories that are nested in one another are rejected, since scanning both would count the nested part twice. Exporting (-o) and database storage (--db) accept a single directory only.

Modes

Gdu has three modes: interactive (default), non-interactive and export.

Non-interactive mode is started automatically when TTY is not detected (using go-isatty), for example if the output is being piped to a file, or it can be started explicitly by using a flag. Use --interactive to disable this automatic fallback and force interactive mode.

In non-interactive mode (and without --top and --depth flags), gdu uses a memory-efficient analyzer that only tracks top-level directory totals. This means memory usage stays constant regardless of how large the scanned directory tree is. When --top or --depth flags are used, the full directory tree is built in memory as in interactive mode.

Export mode (flag -o) outputs all usage data as JSON, which can be later opened using the -f flag. In interactive mode, press Esc or Ctrl+C during a scan to stop scheduling new work and keep the results found so far; pressing Ctrl+C again while the scan is stopping quits gdu. If you would rather have the first Ctrl+C quit gdu outright, use --ctrl-c-quits; Esc keeps working either way.

By default the export includes every attribute, and directories always carry their asize, dsize, and items summary stats so they can be preserved on import. Use --output-attrs=asize,dsize to emit only selected optional attributes; name is always included. Available attributes are asize, dsize, items, mtime, and notreg.

Gdu honors BLOCK_SIZE and BLOCKSIZE in terminal output. BLOCK_SIZE takes precedence; both accept GNU coreutils block-size values such as 1K, kB, human-readable, and si. Explicit size-format flags override these environment variables. Exported JSON always retains raw byte values.

Hard links are counted only once.

Web UI

Gdu can serve a browser-based interface instead of the terminal UI. Run:

gdu --web /some/dir

Gdu scans the directory, prints the URL, and (by default) opens it in your default browser. The interface shows an animated donut chart of the current directory's contents alongside a sortable table with size bars, breadcrumb navigation, and a disk-usage/apparent-size toggle. Switch to the full-window treemap to explore the complete nested subtree, select files or directories, and double-click a directory to open it. Details too small to display are folded into their nearest visible parent directory. Scan progress is streamed live while the analysis runs.

In the treemap, press O to reveal the selected item in the system file manager, D (or Delete) to permanently delete it after confirmation, or ? to show the keyboard shortcuts. The deletion dialog can suppress further confirmations for the current browser session. The --no-delete flag and filtered-scan deletion restrictions apply to the web UI as well as the terminal UI. Reveal remains available with --no-delete because it does not modify scanned data. To deliberately allow deletion while filters are active, set GDU_ALLOW_DELETE_WITH_FILTER=1; the displayed tree may then omit files that are still present on disk.

By default the server binds to localhost on a random free port. Use --web-listen (or the web.listen config option) to pin a fixed address.

The compiled web assets are embedded in the binary, so no extra files or network access are required.

Security: browsing is read-only and requires no authentication, so anyone who can reach the port sees file names and sizes - keep it bound to localhost (the default). Reveal and delete actions need more: a request that both originates from a loopback address and carries a random token, generated fresh for each server run and never served over the API. The URL is printed to this process's terminal and passed to the configured browser launcher. On Linux, a cold-started browser may retain that URL in its world-readable command line; custom browser commands may do the same on any platform. On a multi-user machine, use --web-open=false and open the printed URL from an already-running browser. Pages on another origin or browser tab are rejected even if they can reach the port. Binding to a non-loopback address makes scan details reachable by other hosts on the network and prints a warning.

File flags

Files and directories may be prefixed by a one-character flag with following meaning:

  • ! An error occurred while reading this directory.

  • . An error occurred while reading a subdirectory, size may be not correct.

  • @ File is symlink or socket. Symlinks can be shown as name -> target (the link target is displayed next to the name, like ls -l).

  • H Same file was already counted (hard link).

  • e Directory is empty.

Configuration file

Gdu can read (and write) YAML configuration file.

$HOME/.config/gdu/gdu.yaml and $HOME/.gdu.yaml are checked for the presence of the config file by default.

See the full list of all configuration options.

Examples

  • To configure gdu to permanently run in gray-scale color mode:
echo "no-color: true" >> ~/.gdu.yaml
  • To set default sorting in configuration file:
sorting:
    by: name // size, name, itemCount, mtime
    order: desc
  • To configure gdu to set CWD variable when browsing directories:
echo "change-cwd: true" >> ~/.gdu.yaml
  • To configure the web UI (bind address and browser behavior):
web:
    listen: "localhost:8080"  # empty (default) = localhost + random free port
    open-browser: true        # open the default browser on start
    browser: ""               # override launcher command; empty = OS default
  • To save the current configuration
gdu --write-config

Styling

There are wide options for how terminals can be colored. Some gdu primitives (like basic text) adapt to different color schemas, but the selected/highlighted row does not.

If the default look is not sufficient, it can be changed in configuration file, e.g.:

style:
    selected-row:
        text-color: black
        background-color: "#ff0000"
    marked:
        text-color: white
        background-color: "#6600cc"

Deletion in background and in parallel (experimental)

Gdu can delete items in the background, thus not blocking the UI for additional work. To enable:

echo "delete-in-background: true" >> ~/.gdu.yaml

Directory items can be also deleted in parallel, which might increase the speed of deletion. To enable:

echo "delete-in-parallel: true" >> ~/.gdu.yaml

Saving analysis data to database

Gdu can store the analysis data to a database file instead of just memory. This allows you to save and reload analysis results later. Both SQLite and BadgerDB are supported.

gdu --db analysis.sqlite /        # saves analysis data to SQLite database
gdu --db analysis.badger /        # saves analysis data to BadgerDB
gdu -r --db analysis.sqlite /     # reads saved data, does not run analysis again

Running tests

make install-dev-dependencies
make test

Profiling

Gdu can collect profiling data when the --enable-profiling flag is set. The data are provided via embedded http server on URL http://localhost:6060/debug/pprof/.

You can then use e.g. go tool pprof -web http://localhost:6060/debug/pprof/heap to open the heap profile as SVG image in your web browser.

Benchmarks

Benchmarks were performed on 90G directory (100k directories, 400k files) on 500 GB SSD using hyperfine. See benchmark target

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Goclidisk-usagefilesystemgolang

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具