2018-07-15 17:24:57 +08:00
|
|
|
# truncate
|
|
|
|
|
|
|
|
> Shrink or extend the size of a file to the specified size.
|
2025-01-18 18:45:33 +05:30
|
|
|
> More information: <https://www.gnu.org/software/coreutils/manual/html_node/truncate-invocation.html>.
|
2018-07-15 17:24:57 +08:00
|
|
|
|
2021-05-20 16:13:41 -04:00
|
|
|
- Set a size of 10 GB to an existing file, or create a new file with the specified size:
|
2018-07-15 17:24:57 +08:00
|
|
|
|
2025-03-26 02:30:50 +02:00
|
|
|
`truncate {{[-s|--size]}} 10G {{path/to/file}}`
|
2018-07-15 17:24:57 +08:00
|
|
|
|
2021-08-15 19:59:09 +02:00
|
|
|
- Extend the file size by 50 MiB, fill with holes (which reads as zero bytes):
|
2018-07-15 17:24:57 +08:00
|
|
|
|
2025-03-26 02:30:50 +02:00
|
|
|
`truncate {{[-s|--size]}} +50M {{path/to/file}}`
|
2018-07-15 17:24:57 +08:00
|
|
|
|
2021-08-15 19:59:09 +02:00
|
|
|
- Shrink the file by 2 GiB, by removing data from the end of file:
|
2018-07-15 17:24:57 +08:00
|
|
|
|
2025-03-26 02:30:50 +02:00
|
|
|
`truncate {{[-s|--size]}} -2G {{path/to/file}}`
|
2019-12-30 14:41:06 +02:00
|
|
|
|
|
|
|
- Empty the file's content:
|
|
|
|
|
2025-03-26 02:30:50 +02:00
|
|
|
`truncate {{[-s|--size]}} 0 {{path/to/file}}`
|
2021-05-25 04:48:17 +10:00
|
|
|
|
|
|
|
- Empty the file's content, but do not create the file if it does not exist:
|
|
|
|
|
2025-03-26 02:30:50 +02:00
|
|
|
`truncate {{[-c|--no-create]}} {{[-s|--size]}} 0 {{path/to/file}}`
|