Directory in the mac filesystem has sub directories with greater size than parent directory

filesystem

I have some weirdness on my mac's filesystem nowadays.

I have a dir in my home dev to store my programs and git repos. Size of the dev is 630 MB. Size of the dev/todos is 637 MB and there a re some other sub dirs in this dev of 175MB and so.

What is the reason for that. Is my mac going crazy or it is git or something?

Best Answer

Depending on who is calculating directory sizes, hard-linked files can easily get counted twice, even though they are really only a single inode and should be counted only once.

The du terminal command is the surest way to find out how much space a directory is really taking. It never counts hard-linked files more than once.

(Caveat. If a file in directory A is hard-linked to a file in directory B, and neither directory is contained in the other, du A and du B will each count the file once, so you cannot just add the reported sizes together and get a meaningful sum. However, du C, where C is a directory that contains both A and B, will count the file only once, arbitrarily deciding whether to count the storage as part of A or as part of B.)