Small utility to list sizes of folders under a specified directory.
Features
- Recursively computes total size (bytes) of files under each directory
- Options for human-readable output, sorting, max depth and minimum size filter
- Works on Linux/WSL; includes notes for OneDrive and Windows path handling
Requirements
- Python 3.8+
Usage
Basic:
python3 dir_sizes.py /path/to/dirHuman-readable, limit depth to immediate children:
python3 dir_sizes.py /path/to/dir --human --max-depth 1Sort by name and show only folders >= 1 MB:
python3 dir_sizes.py /path/to/dir --sort=name --min-size=1048576WSL / Windows paths
If you run this from WSL and have a Windows path like C:\Users\You\OneDrive\Pictures:
- use the WSL-mounted path
/mnt/c/Users/You/OneDrive/Pictures - or convert automatically with
wslpath:
python3 dir_sizes.py "$(wslpath 'C:\\Users\\You\\OneDrive\\Pictures')" --humanNote about OneDrive and Files On-Demand
- If OneDrive uses Files On-Demand (placeholder files), some files may not be physically present until downloaded in Windows. Mark important files as "Always keep on this device" in Windows Explorer before inspecting from WSL.
Performance note
- The script computes sizes by walking directories and summing file sizes. For very large trees it may repeat traversals and be slow. If you need faster/bulk scans, consider a single-pass aggregator or using tools like
du -b/ncdufor interactive inspection.
Contributing
- Open an issue or submit a pull request to improve path handling, performance, or add tests.
License
- No license is included by default. Add a LICENSE file to the repository if you want to make the project public under a specific license.