文件大小与zfs压缩

我通常使用du -ks $DIRECTOY_TREE_ROOT来估计整个目录树的大小,但是当打开zfs压缩时,不能使用这个方法。

ls -l显示的total对于单个目录来说是可以的,但是对目录树得到相同结果最简单的方法是什么?

编辑:

操作系统是Solaris 10。

我正在寻找真正的文件大小,而不是磁盘上使用的空间。

这应该只是工作:

 find . -type f -exec ls -l {} + | nawk '{s=s+$5} END {print s}' 

只要用du -b例子:

#du -sh。

215G。

#du -sbh。

344G。

可以使用参数'-ls'直接从命令'find'获得文件大小和近似磁盘使用率。

  function lsdu() ( export SEARCH_PATH=$* if [ ! -e "$SEARCH_PATH" ]; then echo "ERROR: Invalid file or directory ($SEARCH_PATH)" return 1 fi find "$SEARCH_PATH" -ls | gawk --lint --posix ' BEGIN { split("B KB MB GB TB PB",type) ls=hls=du=hdu=0; out_fmt="Path: %s \n Total Size: %.2f %s \n Disk Usage: %.2f %s \n Compress Ratio: %.4f \n" } NF >= 7 { ls += $7 du += $2 } END { du *= 1024 for(i=5; hls<1; i--) hls = ls / (2^(10*i)) for(j=5; hdu<1; j--) hdu = du / (2^(10*j)) printf out_fmt, ENVIRON["SEARCH_PATH"], hls, type[i+2], hdu, type[j+2], ls/du } ' ) 

一些示例命令和输出:

 -bash-3.00# lsdu test_sloccount/ Path: test_sloccount/ Total Size: 30.90 MB Disk Usage: 1.43 MB Compress Ratio: 21.6250 

这个oneliner应该产生预期的结果:

find $DIRECTOY_TREE_ROOT -type d -exec ls -l '{}' \; | awk '/^total\ .[0-9]+$/ { sum+=$(NF) }END{ print sum }'

我没有一个ZFS分区来testing它,但在我的ext4分区上,它输出的结果与du -ks相同。

男人杜可能会在这里帮助:

  --apparent-size print apparent sizes, rather than disk usage; although the apparent size is usually smaller, it may be larger due to holes in (`sparse') files, internal fragmenta- tion, indirect blocks, and the like 

为了完整起见,我将把这个问题的答案包含在FreeBSD中。 据man du

  -A Display the apparent size instead of the disk usage. This can be helpful when operating on compressed volumes or sparse files.