File size with zfs compression

Solution 1:

This should just work:

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

Solution 2:

Just use du -b example:

# du -sh .
215G    .

# du -sbh .
344G    .

Solution 3:

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 

Solution 4:

This oneliner should produce the desired result:

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

I don't have a ZFS partition to test it on, but on my ext4 partition it outputs the same result as du -ks.