Back to the command reference

truncate

FilesAdvanced In simulator In real Linux

Shrink or extend a file to a given size

Name: truncate

You can practise it right away in the simulator, and use it in real Linux mode too.

Description

truncate shrinks or extends a file to a given size. Shrinking discards data; extending fills with holes that take no disk space. truncate -s 0 empties a log that a program is still writing to, without deleting it.

Syntax

truncate OPTION... FILE...

Common options

-s / --size SIZETarget size, e.g. 0, 10M, +1K
-c / --no-createDo not create missing files
-r / --reference FILEMake it as large as FILE

Examples

  • $ truncate -s 0 app.log

    Empty a log file but keep it

    Explain
  • $ truncate -s 1G disk.img

    Create a 1 GB empty file

    Explain

Related