Files and folders

The truncate command

Changes a file size: shrinks it or pads it up to the size you ask.

Syntax

truncate -s <tamaño> <archivo>

Most useful options

-sFinal size (+ and - to grow or shrink)

Copy-ready examples

$ touch f.txtCreate the file
$ truncate -s 10 f.txtLeave it at 10 bytes
$ truncate -s 0 f.txtEmpty it

You can try them in the browser terminal: it does not touch your computer.

Typical mistakes

  • Careful! Truncating a file deletes the excess; it is not reversible.

Related commands

FAQ

Are truncating and deleting the same?

No: truncating changes the size; deleting removes the file.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course