Files

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

  • August 7, 2016

如何輸出實際填充了多少文件標稱大小的數據?就像vmtouch顯示目前記憶體中有多少文件…

我希望工作流程是這樣的:

$ fallocate -l 1000000 data 
$ measure_sparseness data
100%
$ fallocate -p -o 250000 -l 500000  data
$ measure_sparseness
50%

解決方法:使用du -bshdu -sh比較它們。

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.
$ 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

引用自:https://unix.stackexchange.com/questions/301789