truncate

Shrink or extend a file to a size

high risk

interactive breakdown — edit the command and press Explain
$ 
⚠ Risks & cautions
Safer / dry-run alternatives
cp app.log app.log.bak && truncate -s 0 app.logKeep a copy before emptying
logrotate -f /etc/logrotate.d/<app>Let logrotate manage log files
What it does

Sets a file to an exact size. `truncate -s 0 file` empties it without deleting it; extending creates a sparse file.

Common flags
FlagMeaning
-sNew size, e.g. 0, 100M, +1G
-cDo not create missing files
Examples
truncate -s 0 app.logEmpty a log file in place (keeps inode) · explain & risk-check →
truncate -s 1G swapfileCreate a sparse 1 GB file · explain & risk-check →
Related
logrotate dd
Open the full explainer →More in Files & Archives

Reference text is hand-written and may be incomplete — check man truncate for your version. Test destructive commands on a non-production system first.