Forrest logo
back to the truncate tool

truncate:tldr:7ac89

truncate: Empty the file's content, but do not create the file if it does not exist.
$ truncate --no-create --size 0 ${filename}
try on your machine

The command "truncate --no-create --size 0 ${filename}" is used to truncate or empty the content of a file specified by ${filename}.

Here's a breakdown of the command:

  • "truncate" is the command itself, which is used to modify the size of the file.
  • "--no-create" is an option that ensures the file is not created if it doesn't exist. It prevents the creation of a new file with size 0 if ${filename} doesn't exist.
  • "--size 0" is another option that sets the size of the file to 0. This means that the content of the file will be completely removed, leaving it empty.
  • "${filename}" is a placeholder that should be replaced with the actual name and path of the file you want to truncate or empty.

Overall, this command is used to instantly delete the contents of a file, making it empty while preserving the file itself.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the truncate tool