Find Related products on Amazon

Shop on Amazon

Unix files have (at least) two sizes

Published on: 2025-04-21 17:18:12

I'll start by presenting things in illustrated form: ; ls -l testfile -rw-r--r-- 1 cks 262144 Apr 13 22:03 testfile ; ls -s testfile 1 testfile ; ls -slh testfile 512 -rw-r--r-- 1 cks 256K Apr 13 22:03 testfile The two well known sizes that Unix files have are the logical 'size' in bytes and what stat.h describes as "the number of blocks allocated for this object", often converted to some number of bytes (as ls is doing here in the last command). A file's size in bytes is roughly speaking the last file offset that has been written to in the file, and not all of the bytes covered by it may have actually been written; when this is the case, the result is a sparse file. Sparse files are the traditional cause of a mismatch between the byte size and the number of blocks a file uses. However, that is not what is happening here. This file is on a ZFS filesystem with ZFS's compression turned on, and it was created with ' dd if=/dev/zero of=testfile bs=1k count=256 '. In ZFS, zeroes compress ... Read full article.