Directory Size Calculator
Estimate total directory size from file counts and average file sizes.
Inputs
Estimated Total Size (incl. overhead)
1.22 GiB
Raw Data Size (file bytes only)
1.22 GiB
Allocated Size (block-rounded)
1.22 GiB
Metadata + Slack Overhead (bytes)
2,764,800
Overhead Percentage
0.21%
Step by step
Values used
Number of Files = 10,000; Average File Size (KB) = 128; Number of Subdirectories = 50; Filesystem Block Size (bytes) = 4096 (4K, ext4/xfs default)
Total estimated size
total ≈ file_count × ceil(avg_size / block_size) × block_size + subdirs × block_size + file_count × 256
Estimated Total Size (incl. overhead)
= 1.22 GiB
Raw Data Size (file bytes only)
= 1.22 GiB
Allocated Size (block-rounded)
= 1.22 GiB
Metadata + Slack Overhead (bytes)
= 2,764,800
Overhead Percentage
= 0.21
How it works
The `du` command reports space actually allocated on disk, which is always ≥ the sum of file byte sizes because every file consumes whole filesystem blocks (block-rounding / 'slack space'), and every directory entry and inode carries its own metadata. This calculator estimates total = allocated_data + directory_metadata + inode_metadata, so you can sanity-check `du -sh` output against a rough file-count × average-size model before running it on a live filesystem.
Formula
Total estimated size
total ≈ file_count × ceil(avg_size / block_size) × block_size + subdirs × block_size + file_count × 256
- n
- file count
- s
- average file size
- b
- block size
- d
- subdirectory count
Frequently Asked Questions
Why does du report a bigger size than ls -l sums to?
ls -l shows exact byte sizes; du reports blocks actually allocated on disk. A 100-byte file on a filesystem with 4096-byte blocks still consumes one full 4096-byte block, so many small files inflate du's total well above the sum of their logical sizes.
How much does having many small files hurt disk usage?
Block rounding (slack space) is worst for files much smaller than the block size — a 1KB file on 4K blocks wastes 3KB. Millions of small files also multiply inode and directory-entry metadata overhead, which is why archiving small files into a tar or using a filesystem with tail-packing (like Btrfs or ReiserFS) reduces total usage.
Does this replace running du -sh directly?
No — this gives a planning estimate before you have access to the filesystem (e.g. sizing a migration or a new volume). For an authoritative number on an existing directory, always run du -sh or du --apparent-size for the raw byte total.