Main menu:


June 2015
M T W T F S S
« Apr   Dec »
1234567
891011121314
15161718192021
22232425262728
2930  

Archives

The mystery of growing folder sizes

I tested something yesterday. I booted to my rescue USB disk and mounted the disk where I have Linux installed.
I ran cp -rap usr usr-new which preserves everything including symlinks, ownership, permissions, etc…
Then ran a script that md5sums all the files in usr and usr-new.

cd usr && find -type f -exec md5sum “{}” \; > ../md5sum.usr

cd ../usr-new && find -type f -exec md5sum “{}” \; > ../md5sum.usr-new

The checksum files were identical which means the new copy is intact.
But…running du -s -BK in both folders revealed that the old folder is almost 2MB larger in size.
After some investigation, I learned that a directory in Linux filesystems carries a list of the inodes pointing to the files in that directory. Apparently ext4 doesn’t delete pointers to files from a directory when the files are deleted. It just zeros the pointers. So an empty folder called test is 4K in size on disk but after adding and deleting thousands of files, the folder can grow with time. On a system that keeps getting updated frequently, that means ~2MB of lost space per year which is not much but nevertheless an interesting observation.

Leave a Reply

Your email address will not be published. Required fields are marked *