File size with zfs compression
Just use du -b
example:
# du -sh .
215G .
# du -sbh .
344G .
This should just work:
find . -type f -exec ls -l {} + | nawk '{s=s+$5}
END {print s}'
It is possible to get both file size and approximate disk usage direcly from command 'find' with the parameter '-ls'
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
}
'
)
Some sample command and output:
-bash-3.00# lsdu test_sloccount/
Path: test_sloccount/
Total Size: 30.90 MB
Disk Usage: 1.43 MB
Compress Ratio: 21.6250