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.
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(), , .
.