ファイルの「スパース性」を出力する方法は?

ファイルの「スパース性」を出力する方法は?

ファイルの名目サイズに実際にどれだけのデータがいっぱいになっているかを出力するにはどうすればよいですか?vmtouch現在のメモリにいくつのファイルがあるかを表示するのと同じです。

私はワークフローを次のようにしたいと思います。

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

回避策:du -bshdu -shを使用して比較します。

ベストアンサー1

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

おすすめ記事