fsize-cli 0.2.1

A command-line tool for measuring file and directory size
fsize-cli-0.2.1 is not a library.

fsize

Build Status Crates.io License

fsize computes file and directory sizes from the command line. It walks a path in parallel and sums file sizes, or reports mount-level disk usage (total, used, available) for the filesystem containing a path. Default output is nice, readable text. Raw byte and JSON outputs are available for scripts.

The repository is a Cargo workspace containing two crates: fsize-core (the size-computation and formatting logic) and fsize (the CLI binary built on top of it).

Building

Requires a Rust toolchain supporting the 2024 edition (rustc 1.85+).

cargo build --release

A Nix flake is provided to build targets corresponding to the release CI (Linux x86_64/aarch64/armv7/riscv64, macOS, Windows):

nix build

To install from crates.io:

cargo install fsize-cli

The package is published as fsize-cli because the name fsize is already taken on crates.io by an unrelated crate. The installed binary remains named fsize.

Pre-built binaries are attached to each release.

Usage

-b, --binary              base-2 (1024) units instead of base-10 (1000)
-r, --raw, --byte         exact byte count, no unit conversion
-i, --info                entry type (F/D/L) and last-modified time
-m, --metadata            entry's own size via stat(), no recursive walk
-d, --disk-usage          mount-level total/used/available for the
                          filesystem containing PATH
-u, --unit <UNIT>         force a unit, e.g. KB, MiB, GB
    --exclude <PATTERN>   skip entries matching PATTERN (glob, repeatable)
    --max-depth <N>       limit recursion to N directories
-L, --follow-symlinks     follow symlinks while walking
    --json                JSON output
-h, --help
-V, --version

--raw/--byte and --unit/--binary are mutually exclusive. --metadata and --disk-usage are mutually exclusive. Combining exclusive flags causes a usage error (exit code 2).

The -m flag reports the size of PATH itself via stat. The -d flag reports the size of the filesystem containing PATH. Neither flag performs the recursive content walk executed by plain fsize PATH.

Examples

fsize file.txt               |   24 KB
fsize -b file.txt            |   20 KiB
fsize -r file.txt            |   24576
fsize -u MiB file.txt        |   0.02 MiB
fsize -i file.txt            |   24 KB F Jun 24 17:32 UTC
fsize -i some-dir/           |   1.2 GB D Jun 24 17:32 UTC
fsize file1.txt file2.txt
12 B      file1.txt
50 KB     file2.txt
50.01 KB  total
fsize --exclude 'target' --max-depth 3 .
fsize -d /
/   total 512.00 GB   used 210.34 GB   available 301.66 GB   (41.1% used)
fsize --json some-dir/

Benchmarks

Measured against GNU du and diskus on a ~77 GB /home directory, page cache warm, single run.

Stripped binary size:

fsize 0.1.1    826.42 KB
fsize 0.2.0    919.07 KB
diskus         932.42 KB
GNU du         1.6 MB

Wall-clock time (real/user/sys):

fsize 0.1.1    6.918s   3.271s   7.617s
fsize 0.2.0    4.805s   4.874s   7.785s
diskus         6.816s   7.760s  11.956s
GNU du         5.641s   1.673s   3.819s

The user + sys time for fsize 0.2.0 is 12.7s against a 4.8s wall clock, reflecting parallel directory traversal across multiple threads. GNU du runs single-threaded with a 1:1 ratio.

Reported size, in bytes:

fsize 0.1.1    77,661,965,054
fsize 0.2.0    77,662,366,082
diskus         71,502,820,852
GNU du         71,502,838,897

fsize reports approximately 6.16 GB more than diskus and du. du and diskus deduplicate by inode to count hard linked files once. fsize sums directory entries independently without checking inode identity, causing hardlink double counting.

Contributing

Bug reports and patches go through GitHub Issues.