$linuxjunkies
>

sparse file

also: hole, sparse storage

A file that contains large blocks of empty space (null bytes) but only uses disk space for the actual data and metadata, not the gaps. Sparse files save storage by not physically writing zeros to disk.

A sparse file is a file that appears to have a certain size to applications, but doesn't actually consume that much physical disk space. The filesystem stores only the non-zero data blocks and records where gaps exist, rather than writing out explicit null bytes.

When you read a sparse file, the OS transparently returns zeros for the unwritten portions, making the file appear complete. This is useful for virtual machine disk images, database files, and backup archives where you might allocate large regions that remain mostly empty.

For example, if you create a 1 GB file and only write data to the first 1 MB and last 1 MB, a sparse file stores only ~2 MB on disk. Running ls -l shows the logical size (1 GB), but du reveals the actual space used (~2 MB).

Not all filesystems support sparse files equally, and copying a sparse file with naive tools may expand it to its full logical size. Use tools like cp --sparse=always or rsync to preserve sparseness.

Related terms