On my Ubuntu system, using ext4, du -b file
gives the size in bytes of an actual file, and du -b dir
gives the size in bytes of the file(s) + directory overhead, The overhead is, in my case, multiples of 4096 bytes ..
This overhead increases as the number of files increases.
Note: even if files are deleted, the directory overhead remains at the higher level it was at before the flles were deleted..
I haven't tried rebooting, to see if it reverts, but in either case, this means that the directory size varies depending on historic circumstances.
Tallying each files size may be the best option for an accurate value of the total file sizes.
The following script totals all file sizes (in bytes)..
For OS X, if you don't have the -b
opton for 'du', you can use stat
instead .(if you have it :)... The commented line shows the Ubuntu stat
alternative to du -b
;
unset total
while IFS= read -r -d $'\0' rf; do
# (( total += $(stat "$rf" | sed -nre 's/^ Size: ([0-9]+).*/\1/p') ))
(( total += $(du -b "$rf" | cut -f 1) ))
done < <(find . -type f -name '*' -print0)
echo $total