Menu

1 / 2

Why du and Finder show different folder sizes

DEV Community: rust·Hanako H.·7 days ago
#yuMU3k5y
#devtorust#devto#dev#folder#disk
Reading 0:00
15s threshold

Run du -sh on a folder and compare it with Finder's size, and the two often disagree, sometimes by gigabytes. Neither is wrong. They answer different questions: how long the files are, and how much of the disk they occupy. When the disk is full only the second one matters, and getting it right takes more than adding up st_size .

The rules below are the ones the Disk screen in the osFoundry desktop app follows. Its scanner is a short Rust function over std::fs , and the same logic fits in about 40 lines of Python. All the numbers come from a test folder on an APFS volume with 4 KB allocation blocks.

Count blocks, not bytes

st_size is the file's length. st_blocks is how many 512-byte units the file system has allocated to it, whatever the volume's real block size is.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.