Calculating size of a directory? (disk space usage)
We need to calucalate the size of a directory. Right now we are doing stat() on the individual files in the directory, and adding up their sizes to get te size of the directory. Is there a more efficient way to do this?Appraciate your thoughts and ideas.Venu
[279 byte] By [
venu100a] at [2007-11-27 8:21:06]

# 1
Nope, tats exactly what du does.The only other way to get sizes is df to get the size of the filesystem. So if you make the directory a separate filesystem, yopu can do it that way.Of course with zfs, its pretty easy to have as many filesystems as you want...
# 3
Its not bad for large files. If you have a million small files it adds up.
But at least you don't have to step through the file byte at a time like "wc" does.
I theory I suppose could store the cumulative size of directory hierarchy with a directory.
But that would mean that for every write to any file, you would have to update the size in every parent directory all the way up to the root.
Which would have disastrous performance implications.