https://github.com/mlange-42/dirstat
Command line tool to analyze and visualize disk usage
https://github.com/mlange-42/dirstat
cli-app visualization
Last synced: 7 months ago
JSON representation
Command line tool to analyze and visualize disk usage
- Host: GitHub
- URL: https://github.com/mlange-42/dirstat
- Owner: mlange-42
- License: mit
- Created: 2022-12-14T16:05:24.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-23T12:06:26.000Z (over 1 year ago)
- Last Synced: 2024-10-21T17:52:29.409Z (about 1 year ago)
- Topics: cli-app, visualization
- Language: Go
- Homepage:
- Size: 272 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dirstat
[](https://github.com/mlange-42/dirstat/actions/workflows/tests.yml)
A command line tool for analyzing and visualizing disk usage.

*Example visualizing the Go repository using a treemap*

*Example visualizing the dirstat repository using a text-based directory tree*
## Installation
**Using Go:**
```shell
go install github.com/mlange-42/dirstat@latest
```
**Without Go:**
Download binaries for your OS from the [Releases](https://github.com/mlange-42/dirstat/releases/).
## Features
* 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
## Usage
Get help:
```shell
dirstat -h
dirstat -h
```
### Basic usage
To view a text-based directory tree, use without a subcommand:
```shell
dirstat
```
#### Options
Run for a different directory (paths can be absolute or relative):
```shell
dirstat --path ../..
```
Analyze with a different depth than the default plain list:
```shell
dirstat --depth 2
```
Exclude files and directories by glob patterns:
```shell
dirstat --exclude .git,*.exe
```
Aggregate by file extensions:
```shell
dirstat -x
```
Sort by size (or count, or age):
```shell
dirstat --sort size
```
Sort by size and show only the top 90%:
```shell
dirstat --sort size --cutoff 90
```
For more options, see the CLI help `dirstat -h`.
### Treemap
To generate graphical treemaps, use the `treemap` command.
Generate the treemap and write it to `out.svg` (can be viewed with any web browser):
```shell
dirstat treemap > out.svg
```
Immediately open the created SVG with the default associated program (ideally a web browser):
```shell
dirstat treemap > out.svg && out.svg
```
#### Options
Statistics over file extensions:
```shell
dirstat treemap -x > out.svg
```
Size boxes by file count instead of size:
```shell
dirstat treemap --count > out.svg
```
Produce CSV output for use with [`github.com/nikolaydubina/treemap`](https://github.com/nikolaydubina/treemap):
```shell
dirstat treemap --csv
```
For more options to customize the treemap, see the CLI help `dirstat treemap -h`.
### JSON
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`:
```shell
dirstat json > out.json
```
Read the JSON instead of running an analysis, and print the directory tree in plain text format:
```shell
dirstat --path out.json
```
## References
* Uses [`github.com/nikolaydubina/treemap`](https://github.com/nikolaydubina/treemap) for treemap SVG rendering