I would like to know, how much is a sparse file really using on the disk.
ls, statand similar commands all seem showing its virtual size, i.e. with the holes.
I want to know the real disk usage of the file, without the holes.
How can I do that?
I would like to know, how much is a sparse file really using on the disk.
ls, statand similar commands all seem showing its virtual size, i.e. with the holes.
I want to know the real disk usage of the file, without the holes.
How can I do that?
stat’s “Blocks” field shows the allocated blocks, which will be smaller than the apparent size with sparse files:
$ truncate -s 1g test.1g
$ stat test.1g
File: test.1g
Size: 1073741824 Blocks: 0 IO Block: 4096 regular file
…
du and ls can also be used:
$ ls -s test.1g
0 test.1g
$ du test.1g
0 test.1g
If you’re not seeing this kind of results, then your file isn’t really sparse, or its sparseness is hidden by a layer of indirection (some network file systems or FUSE file systems for example).
ext4 filesystem, a 1G file has 77824 extra bytes allocated.