Shrink or extend a file to a size
high risk
cp app.log app.log.bak && truncate -s 0 app.logKeep a copy before emptyinglogrotate -f /etc/logrotate.d/<app>Let logrotate manage log filesSets a file to an exact size. `truncate -s 0 file` empties it without deleting it; extending creates a sparse file.
| Flag | Meaning |
|---|---|
-s | New size, e.g. 0, 100M, +1G |
-c | Do not create missing files |
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 →Reference text is hand-written and may be incomplete — check man truncate for your version. Test destructive commands on a non-production system first.