Truncate files on Linux/Mac OS

A quick way to truncate a file to zero length without affecting any other attributes (owner, permissions, and so on)? Here goes…
In the terminal window, type the following command at the prompt

: > filename.ext

The file called filename.ext will be reduced to zero bytes (emptied, basically). Everything else stays as it is, apart from the last-modified timestamp.

Leave a comment

Your email address will not be published. Required fields are marked *