Linux "fallocate" Command Line Options and Examples
manipulate file space

fallocate is used to manipulate the allocated disk space for a file, either to deallocate or preallocate it. For filesystems which support the fallocate 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.


Usage:

fallocate [-c|-p|-z] [-o offset] -l length [-n] filename


    fallocate -d [-o offset] [-l length] filename


    fallocate -x [-o offset] -l length filename






Command Line Options:

-c
Removes a byte range from a file, without leaving a hole. The byte range to be collapsed starts at offset and continues forlength bytes. At the completion of the operation, the contents of the file starting at the location offset+length will beappended at the location offset, and the file will be length bytes smaller. The option --keep-size may not be specified forthe collapse-range operation.Available since Linux 3.15 for ext4 (only for extent-based files) and XFS.
fallocate -c ...
-d
Detect and dig holes. This makes the file sparse in-place, without using extra disk space. The minimum size of the holedepends on filesystem I/O block size (usually 4096 bytes). Also, when using this option, --keep-size is implied. If no rangeis specified by --offset and --length, then the entire file is analyzed for holes.You can think of this option as doing a "cp --sparse" and then renaming the destination file to the original, without the needfor extra disk space.See --punch-hole for a list of supported filesystems.
fallocate -d ...
-i
Insert a hole of length bytes from offset, shifting existing data.
fallocate -i ...
-l
Specifies the length of the range, in bytes.
fallocate -l ...
-n
Do not modify the apparent length of the file. This may effectively allocate blocks past EOF, which can be removed with atruncate.
fallocate -n ...
-o
Specifies the beginning offset of the range, in bytes.
fallocate -o ...
-p
Deallocates space (i.e., creates a hole) in the byte range starting at offset and continuing for length bytes. Within thespecified range, partial filesystem blocks are zeroed, and whole filesystem blocks are removed from the file. After a suc‐cessful call, subsequent reads from this range will return zeroes. This option may not be specified at the same time as the
fallocate -p ...
--zero-range
Supported for XFS (since Linux 2.6.38), ext4 (since Linux 3.0), Btrfs (since Linux 3.7) and tmpfs (since Linux 3.5).
fallocate --zero-range ...
-v
Enable verbose mode.
fallocate -v ...
-x
Enable POSIX operation mode. In that mode allocation operation always completes, but it may take longer time when fast alloca‐tion is not supported by the underlying filesystem.
fallocate -x ...
-z
Zeroes space in the byte range starting at offset and continuing for length bytes. Within the specified range, blocks arepreallocated for the regions that span the holes in the file. After a successful call, subsequent reads from this range willreturn zeroes.Zeroing is done within the filesystem preferably by converting the range into unwritten extents. This approach means that thespecified 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.
fallocate -z ...
-V
Display version information and exit.
fallocate -V ...
-h
Display help text and exit.AUTHORSEric Sandeen ⟨sandeen@redhat.com⟩Karel Zak ⟨kzak@redhat.com⟩
fallocate -h ...