A command line tool for analyzing and visualizing disk usage.
Example visualizing the Go repository using a treemap
![](https://user-images.githubusercontent.com/44003176/208779980-c366184f-f38c-4b13-b266-fa203e068962.png)
Example visualizing the dirstat repository using a text-based directory tree
Using Go:
go install github.com/mlange-42/dirstat@latest
Without Go:
Download binaries for your OS from the Releases.
- Visualize disk usage as text-based tree or as graphical treemap (SVG)
- Optional visualization of directory content by file extension
- Exclusion of files and directories by glob patterns
- Adjustable depth for individual display vs. aggregation
- Write analysis to JSON and re-read for visualization, for handling large directories
- Determines the size of large directories 4x faster than Windows Explorer, and 3x faster than PowerShell
Get help:
dirstat -h
dirstat <command> -h
To view a text-based directory tree, use without a subcommand:
dirstat
Run for a different directory (paths can be absolute or relative):
dirstat --path ../..
Analyze with a different depth than the default plain list:
dirstat --depth 2
Exclude files and directories by glob patterns:
dirstat --exclude .git,*.exe
Aggregate by file extensions:
dirstat -x
Sort by size (or count, or age):
dirstat --sort size
Sort by size and show only the top 90%:
dirstat --sort size --cutoff 90
For more options, see the CLI help dirstat -h
.
To generate graphical treemaps, use the treemap
command.
Generate the treemap and write it to out.svg
(can be viewed with any web browser):
dirstat treemap > out.svg
Immediately open the created SVG with the default associated program (ideally a web browser):
dirstat treemap > out.svg && out.svg
Statistics over file extensions:
dirstat treemap -x > out.svg
Size boxes by file count instead of size:
dirstat treemap --count > out.svg
Produce CSV output for use with github.com/nikolaydubina/treemap
:
dirstat treemap --csv
For more options to customize the treemap, see the CLI help dirstat treemap -h
.
With subcommand json
, the result of the analysis is written to STDOUT in JSON format.
If piped to a file, it can be re-used for visualization by using it in the --path
flag.
Analyze the current directory and write JSON to out.json
:
dirstat json > out.json
Read the JSON instead of running an analysis, and print the directory tree in plain text format:
dirstat --path out.json
- Uses
github.com/nikolaydubina/treemap
for treemap SVG rendering