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