fallocate - preallocate or deallocate space to a file
fallocate [-c|-p|-z] [-o offset] -l length [-n] filename
fallocate -d [-o offset] [-l length] filename
fallocate -x [-o offset] -l length filename
fallocate is used to manipulate the allocated disk space for a file, either to deallocate or preallocate it. For filesystems which support the fallocate(2) system call, preallocation is done quickly by allocating blocks and marking them as uninitialized, requiring no IO to the data blocks. This is much faster than creating a file by filling it with zeroes.
The exit status returned by fallocate is 0 on success and 1 on failure.
The length and offset arguments may be followed by the multiplicative suffixes KiB (=1024), MiB (=1024*1024), and so on for GiB, TiB, PiB, EiB, ZiB, and YiB (the "iB" is optional, e.g., "K" has the same meaning as "KiB") or the suffixes KB (=1000), MB (=1000*1000), and so on for GB, TB, PB, EB, ZB, and YB.
The options --collapse-range, --dig-holes, --punch-hole, and --zero-range are mutually exclusive.
Available since Linux 3.15 for ext4 (only for extent-based files) and XFS.
A filesystem may place limitations on the granularity of the operation, in order to ensure efficient implementation. Typically, offset and length must be a multiple of the filesystem logical block size, which varies according to the filesystem type and configuration. If a filesystem has such a requirement, the operation will fail with the error EINVAL if this requirement is violated.
You can think of this option as doing a "cp --sparse" and then renaming the destination file to the original, without the need for extra disk space.
See --punch-hole for a list of supported filesystems.
-l, --length length
-o, --offset offset
Supported for XFS (since Linux 2.6.38), ext4 (since Linux 3.0), Btrfs (since Linux 3.7), tmpfs (since Linux 3.5) and gfs2 (since Linux 4.16).
Zeroing is done within the filesystem preferably by converting the range into unwritten extents. This approach means that the specified range will not be physically zeroed out on the device (except for partial blocks at the either end of the range), and I/O is (otherwise) required only to update metadata.
Option --keep-size can be specified to prevent file length modification.
Available since Linux 3.14 for ext4 (only for extent-based files) and XFS.
Eric Sandeen <email@example.com>, Karel Zak <firstname.lastname@example.org>
For bug reports, use the issue tracker at https://github.com/util-linux/util-linux/issues.
The fallocate command is part of the util-linux package which can be downloaded from Linux Kernel Archive https://www.kernel.org/pub/linux/utils/util-linux/.