如何输出文件的“稀疏性”?

Vi.*_*Vi. 15 sparse-files files

如何输出实际填充数据的文件标称大小?就像vmtouch显示当前内存中有多少文件......

我希望工作流程是这样的:

$ fallocate -l 1000000 data 
$ measure_sparseness data
100%
$ fallocate -p -o 250000 -l 500000  data
$ measure_sparseness
50%
Run Code Online (Sandbox Code Playgroud)

解决方法:使用du -bshdu -sh并加以比较。

Vi.*_*Vi. 19

find具有%S格式说明符,甚至被命名为“稀疏”

         %S     File's  sparseness.   This  is  calculated as (BLOCKSIZE*st_blocks / st_size).  The exact value you will get for an ordinary file of a certain
                 length is system-dependent.  However, normally sparse files will have values less than 1.0, and files which use indirect  blocks  may  have  a
                 value which is greater than 1.0.   The value used for BLOCKSIZE is system-dependent, but is usually 512 bytes.   If the file size is zero, the
                 value printed is undefined.  On systems which lack support for st_blocks, a file's sparseness is assumed to be 1.0.
Run Code Online (Sandbox Code Playgroud)
$ fallocate -l 1000000 data
$ find data -printf '%S\n'
1.00352
$ fallocate -p -o 250000 -l 500000  data
$ find data -printf '%S\n'
0.507904
Run Code Online (Sandbox Code Playgroud)