Pathsize

Overview
Pathsize is a small CLI utility that prints the size of a file or directory.
Features
- Show the size of a single file or directory
- Support recursive directory traversal
- Optionally include hidden files and directories
- Output sizes in either raw bytes or human-readable format
Installation
Install the CLI binary with:
go install ./cmd/pathsize
After installation, run:
pathsize <path>
Library usage
The package can also be used as a Go library by importing it from the module root:
import "github.com/CosmoS1X/pathsize"
size, err := pathsize.Get(path, recursive, human, all)
Get returns the formatted size as a string and an error if the path cannot be read.
Parameters:
path — the file or directory to inspect
recursive — if true, directories are traversed recursively
human — if true, the result is formatted in human-readable units
all — if true, hidden files and directories are included in the calculation
Usage
pathsize [options] <path>
Options
-r, --recursive — calculate the size of directories recursively
-H, --human — display sizes in a human-readable format
-a, --all — include hidden files and directories
-h, --help — show help information
Examples
Show the size of a file in bytes:
pathsize testdata/test.txt
Show a directory size recursively:
pathsize -r testdata
Show a human-readable size for a directory:
pathsize -H testdata
Include hidden entries in the calculation:
pathsize -a testdata
Combine multiple flags in one command:
pathsize -raH testdata
The program prints:
<size> <path>
For example:
6B testdata/test.txt