検索: ファイルサイズの制限は同じですが、単位が異なると結果が異なります

検索: ファイルサイズの制限は同じですが、単位が異なると結果が異なります

5 GiB 未満のファイルを一覧表示する次の 2 つのコマンドでは、異なる結果が生成されることに気付きました。

find . -type f -size -5368709120c
find . -type f -size -5G

具体的には、キロバイト単位 ( ) を使用するものは、5368709120cGiB 単位 ( 5G) を使用するものによって返される最大ファイル サイズよりも大きい追加のファイルを返します。

マニュアルページからfind次のことを読みました:

-size n[cwbkMG]
          File uses n units of space.  The following suffixes can be used:
          `b'    for 512-byte blocks (this is the default if no suffix is used)
          `c'    for bytes
          `w'    for two-byte words
          `k'    for Kilobytes (units of 1024 bytes)
          `M'    for Megabytes (units of 1048576 bytes)
          `G'    for Gigabytes (units of 1073741824 bytes)

The size does not count indirect blocks, but it does count blocks 
in sparse files that are not actually allocated.  Bear in mind that the `%k'
and `%b' format specifiers of -printf handle sparse files differently.   The 
`b'  suffix always denotes 512-byte blocks and never 1 Kilobyte blocks, 
which is different to the behaviour of -ls.

したがって、 の単位がG1073741824 であることを考えると、5Gとなるはずです5368709120c。この問題は、スパース ブロックまたは間接ブロックの数え方が原因でしょうか?

ご協力ありがとうございます。

** アップデート **

他にも奇妙なことが見つかりました。返されるファイルが異なるしきい値は、正確に 4 GiB です。

見つかった最大のファイル-5G:

4285018593 bytes = 3.990734548 GiB

最大ないファイルを見つけた人-5G:

4299230968 bytes = 4.003970854 GiB

ファイルは XFS パーティションに保存されます。

meta-data=/dev/mapper/vg_XXXXX_lv isize=256    agcount=197, agsize=268435440 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=52739701760, imaxpct=1
         =                       sunit=16     swidth=256 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=521728, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

答え1

スーパーユーザーの回答を見るカミル

https://superuser.com/a/1351674/27340

関連情報