我正在使用shutil.disk_usage()函数来查找特定路径的当前磁盘使用情况(可用,使用的数量等).据我所知,这是os.statvfs()调用的包装器.我发现它没有给出我期望的答案,与Linux中“du”的输出相比.
出于公司隐私原因,我已经模糊了下面的一些路径,但输出和代码在其他方面都没有被删除.我使用的是Python 3.3.2 64位版本.
#!/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))
哪个输出:
/data/foo/drivecode/me % disk_usage_test.py
Total: 609.60GB
Used: 291.58GB
Total: 609.60GB
Used: 291.58GB
正如