磁盘使用情况摘要,显示大目录/文件
dutree的Python项目详细描述
dutree显示占用最多的目录/文件的摘要 空间。
而不是显示只有文件根的大小,或者 详细信息每个文件,它只显示占用最多的路径 空间。
示例用法:
$ dutree /srv
带注释的输出,其中仅显示总大小的5%的路径 (对于这个数据集大约是4GB):
12.1 G /srv/data/audiofiles/ ^-- audiofiles contains files/dirs with a total of 12.1G but it does NOT contain a single dir or file larger than 4G. 4.3 G /srv/data/callrecordings/unmatched/ 4.5 G /srv/data/fax/ 17.5 G /srv/data/playlists/ 34.4 G /srv/data/twinfield_invoices/1/ 7.8 G /srv/data/* ^-- data contains more files/directories than shown above but those that don't total above 4G are merged into this "leftover" node. that includes everything in /twinfield_invoices/ except for the /1/ subdirectory which has its individual listing above. 32 B /srv/* ^-- only /data/ is in /srv/, but the directory itself also takes up a tiny bit of space ----- 80.6 G TOTAL (86558511658)
注意:目录本身不计算大小,只计算 他们的内容。这解释了与du -sb输出的任何差异。
注意:在具有内置压缩(如zfs)或许多 稀疏文件,您可能需要选中–count blocks选项。这个 应该更好地反映实际使用的大小(并与du -sh对齐)。
库使用:
>>> from dutree import Scanner >>> scanner = Scanner('/srv') >>> tree = scanner.scan(use_apparent_size=True) >>> tree.app_size() 86558511658 >>> len(tree.get_leaves()) 7 >>> leaf0 = tree.get_leaves()[0] >>> leaf0.name() '/srv/data/audiofiles/' >>> leaf0.app_size() / (1024.0 * 1024 * 1024) 12.092280263081193
历史记录
- v1.6
- fix,这样测试也可以与python 3一起工作。
- 修复实际大小的严重错误。 实际大小的计算有时是错误的,它引发了断言 有时,树叶的数量有时会减少。
- v1.5
- 添加外观大小与实际大小。 不赞成node.size()。请改用node.app_size()。 使用node.use_size()获取实际使用的大小。 通过将use_apparent_size=False传递给 scan()。
- 如果我们不能进入目录,就不会死。