truncate
truncate [OPTION]... [FILE]...
Shrink or extend the size of each file to the specified size.
Options
--io-blocks
,-o
-
treat SIZE as the number of I/O blocks of the file rather than bytes (NOT IMPLEMENTED)
--no-create
,-c
-
do not create files that do not exist
--reference=<RFILE>
,-r <RFILE>
-
base the size of each file on the size of RFILE
--size=<SIZE>
,-s <SIZE>
-
set or adjust the size of each file according to SIZE, which is in bytes unless --io-blocks is specified
SIZE is an integer with an optional prefix and optional unit. The available units (K, M, G, T, P, E, Z, and Y) use the following format: 'KB' => 1000 (kilobytes) 'K' => 1024 (kibibytes) 'MB' => 10001000 (megabytes) 'M' => 10241024 (mebibytes) 'GB' => 100010001000 (gigabytes) 'G' => 102410241024 (gibibytes) SIZE may also be prefixed by one of the following to adjust the size of each file based on its current size: '+' => extend by '-' => reduce by '<' => at most '>' => at least '/' => round down to multiple of '%' => round up to multiple of
Examples
Set a size of 10 GB to an existing file, or create a new file with the specified size:
truncate --size 10G {{path/to/file}}
Extend the file size by 50 MiB, fill with holes (which reads as zero bytes):
truncate --size +50M {{path/to/file}}
Shrink the file by 2 GiB, by removing data from the end of file:
truncate --size -2G {{path/to/file}}
Empty the file's content:
truncate --size 0 {{path/to/file}}
Empty the file's content, but do not create the file if it does not exist:
truncate --no-create --size 0 {{path/to/file}}
The examples are provided by the tldr-pages project under the CC BY 4.0 License.
Please note that, as uutils is a work in progress, some examples might fail.