I am trying to find the best way to get the space used by all files in a directory and it's subdirectories. There are many posts about this like this one : Calculating a directory's size using Python?
However the recursive file counting methods and the linux du -sh command recommended in that thread give widely different results. On the same directory with only two files if I count the file sizes alone with any method I get: 864 Bytes
With the linux du -hs command i get 12K bytes!
That is a huge difference anyone knows why?
I kept looking for an answer (which none seems to discuss in the original posts but it is important as it produces big differences) and it has to do with memory block sizes.
The linux du command shows the sie of memory blocks allocated. In my system even the smallest emmeory block is 4k so any file regardless of its size seems to take 4k with the du command: Why Numbers from "du -s" and "df" Disagree