For some reason, when I make a text file on OS X, it's always at least 4kB, unless it's blank. Why is this? Could there be 4,000 bytes of metadata about 1 byte of plain text?

|
For some reason, when I make a text file on OS X, it's always at least 4kB, unless it's blank. Why is this? Could there be 4,000 bytes of metadata about 1 byte of plain text?
|
||||
|
The block size of the file system must be 4 kB. When data is written to a file that is contained in a file system the operating system must allocate blocks of storage to contain the data that will be written to the file. Typically, when a file system is created the storage contained in that file system is segmented into blocks of a fixed size. This Wikipedia article briefly explains this process. The underlying block size of the file system for this file must have a 4K byte block size. This file is using 1 4K block and only one byte within that block contains actual data. |
|||||
|
|
All file systems have a cluster or block size, or the smallest amount of disk space that can be allocated to hold a file. Even if the actual file size is smaller than the cluster/block size, it will still consume one cluster, or 4K on your file system. The cluster size depends on the file system, and the file system options. If it contains zero bytes, as Gilles pointed out, it uses zero blocks/clusters but one inode on typical *nix file systems, which better answers the caveat, "unless it's blank." |
|||||||
|
|
An little experiment to help illustrate this: First, let's see what the actual block size of my root ext4 (LVM) partition is:
It is 4096 (4 KiB), as expected. Now, let's create three files: The first is zero bytes, the second is just one byte, and the third is 4 KiB (the block size):
Two things can be noted here:
|
|||||||||||||||||
|
:P– tkbx Jan 22 at 12:26