Calculate file and directory sizes from the command line
Project description
filesize-cli
A zero-dependency command-line tool for calculating file and directory sizes with intelligent unit formatting and recursive traversal support.
Features
- Intelligent Unit Detection: Automatically selects the most appropriate unit (B, KB, MB, GB, TB) based on file size
- Recursive Directory Sizing: Calculate total size of directories including all subdirectories with
-r - Clean Raw Output: Get raw byte sizes without formatting using
-cflag - Force Specific Units: Display sizes in specific units with
-u - Zero External Dependencies: Uses only Python standard library (
argparse,pathlib,typing,sys) - Robust Error Handling: Gracefully handles permission errors, missing files, and edge cases
- Cross-Platform: Works on Windows, macOS, and Linux
- Well-Tested: Comprehensive test suite with >90% coverage
Requirements
- Python 3.9 or higher
Installation
# From PyPI
pip install filesize-cli
# Using pipx (isolated environment)
pipx install filesize-cli
# From source
git clone https://github.com/thaikolja/filesize-cli.git
cd filesize-cli
pip install .
Usage
# Show size of a file (auto unit detection)
filesize document.pdf
# Show size of a directory
filesize ~/Documents
# Recursive directory sizing
filesize -r ~/Projects
# Force specific unit
filesize -u mb image.jpg
# Raw bytes output
filesize -c data.bin
# Multiple paths
filesize file1.txt file2.txt directory/
Command Reference
Arguments
| Argument | Description |
|---|---|
PATH [PATH ...] |
One or more files or directories to analyze (required) |
Options
| Option | Description |
|---|---|
-u, --unit {b,kb,mb,gb,tb} |
Force display in specific unit |
-c, --clean |
Display raw sizes in bytes only |
-r, --recursive |
Recurse into subdirectories |
-v, --version |
Show version and exit |
-h, --help |
Show help message and exit |
Exit Codes
| Code | Meaning |
|---|---|
0 |
Success |
1 |
General error |
130 |
Operation cancelled (Ctrl+C) |
Examples
Auto Unit Detection
$ filesize photo.jpg
photo.jpg: 2.45 MB (1 file)
Force Specific Unit
$ filesize -u kb document.pdf
document.pdf: 1,247.00 KB (1 file)
Raw Byte Output
$ filesize -c config.json
1543
Directory Sizing
# Non-recursive (top-level only)
$ filesize ~/Documents
/Users/kolja/Documents: 45.20 MB (12 files)
# Recursive (including subdirectories)
$ filesize -r ~/Documents
/Users/kolja/Documents: 1.23 GB (1,456 files)
Programmatic Usage
from filesize_cli.cli import FilesizeCLI
cli = FilesizeCLI()
size_info = cli.get_size('/path/to/file.txt')
print(size_info) # /path/to/file.txt: 1.23 MB (1 file)
Development
Setup
git clone https://github.com/thaikolja/filesize-cli.git
cd filesize-cli
python -m venv venv
source venv/bin/activate
pip install -e ".[dev]"
pre-commit install
Commands
| Action | Command |
|---|---|
| format | black src tests && isort src tests |
| lint | black --check src tests && isort --check-only src tests && flake8 src tests && mypy src |
| test | pytest |
| coverage | pytest --cov=filesize_cli --cov-report=html |
| build | python -m build |
Contributing
Contributions are welcome. Please see CONTRIBUTING.md for guidelines.
Changelog
See CHANGELOG.md for a detailed history of changes.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file filesize_cli-2.3.0.tar.gz.
File metadata
- Download URL: filesize_cli-2.3.0.tar.gz
- Upload date:
- Size: 19.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9da68423b3a0acabaa3cde993468368a6e2eb780d6ac0e1b5b28c2406411326
|
|
| MD5 |
2916b8ef87994f3d773e9f69193e45ef
|
|
| BLAKE2b-256 |
e38137115e140fedc4ca03c1d9dacadda902f38250ba923f40595c986c3c1247
|
File details
Details for the file filesize_cli-2.3.0-py3-none-any.whl.
File metadata
- Download URL: filesize_cli-2.3.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
284a9c19dcd45f20ad35856adf45420b57cd92324acc893509ac4f8e8d53d124
|
|
| MD5 |
cbd8cdaeb6f06c2fed02bdf951ce6fe3
|
|
| BLAKE2b-256 |
1c25346935a8584112f1f3c053c3b0e8e12dff7224fa1414d52e4860aaaeb3b6
|