A sparse file is a type of file in which we try to efficiently occupy the file system space in cases where the file is mostly empty.
The advantage of sparse files is that the physical space in the file system is only allocated when it is actually needed: therefore you save space and you can create large files even if there is insufficient free space in the file system.
One of the disadvantages of using sparse files:
They can become fragmented, as the space in the file system is allocated gradually as the empty areas are filled, so it is not necessarily contiguous. Information about free space in the file system can be misleading when considering the apparent size of sparse files.
A typical use of sparse files is for testing network connections or for hard disk benchmarks: large files are created with a simple command, which will then be used to understand the copy/transfer speed of the various devices.
Creation on Windows
From the command prompt, navigate to a folder
execute the command
fsutil file createnew <filename> <length>
the length must be entered in Byte, for example:
fsutil file createnew myfile.txt 1000000000 (=1GB)
fsutil file createnew myfile.txt 2500000000 (=2.5 GB)
Creation on Linux
dd if=$INPUT-FILE of=$OUTPUT-FILE bs=$BLOCK-SIZE count=$NUM-BLOCKS
$INPUT-FILE must always be /dev/zero for big files (empty).
The total size of the sparse file will be $BLOCK-SIZE * $NUM-BLOCKS.
The new file will be named as $OUTPUT-FILE.
dd if=/dev/zero of=sparse_file_test bs=1024 count=1
bs is the output size in Byte.