Appearance of a mismatch in the shutil.disk_usage () file

Hi people StackOverflow, Long time reader, first time poster. Hope I have all the information here to ask a useful question.

I use the shutil.disk_usage () function to find the current disk usage of a specific path (number of available, used, etc.). As far as I can find, this is a wrapper around os.statvfs () calls. I find that it does not give the answers I would expect compared to the output of "du" on Linux.

I have hidden some of the paths below for reasons of company privacy, but the output and code will not be processed otherwise. I am using the 64-bit version of Python 3.3.2.

#!/apps/python/3.3.2_64bit/bin/python3

# test of shutils.diskusage module
import shutil

BytesPerGB = 1024 * 1024 * 1024

(total, used, free) = shutil.disk_usage("/data/foo/")
print ("Total: %.2fGB" % (float(total)/BytesPerGB))
print ("Used:  %.2fGB" % (float(used)/BytesPerGB))

(total1, used1, free1) = shutil.disk_usage("/data/foo/utils/")
print ("Total: %.2fGB" % (float(total1)/BytesPerGB))
print ("Used:  %.2fGB" % (float(used1)/BytesPerGB))

What outputs:

/data/foo/drivecode/me % disk_usage_test.py
Total: 609.60GB
Used:  291.58GB
Total: 609.60GB
Used:  291.58GB

, , "" , .

/data/foo/drivecode/me % du -sh /data/foo/utils
2.0G    /data/foo/utils

"", , Python . , , Linux, .:)

( , SO), disk_usage, . , "du", MUCH, , shutil.disk_usage(), , .

.

+4
2

, statvfs . , , . , , , , , .

, /data/foo/utils, , . . , , used shutil:

used = (st.f_blocks - st.f_bfree) * st.f_frsize

:

fsblkcnt_t     f_blocks;   /* size of fs in f_frsize units */
fsblkcnt_t     f_bfree;    /* # free blocks */
unsigned long  f_frsize;   /* fragment size */

, .

, , du . GNU coreutils du .

+5

shutil.disk_usage (.. , ), . df /path/to/mount, du /path/to/files. , .

: total, used free, , .

+4

All Articles