Truncating a file

Truncating a file is when you trim a file down to a maximum length. Truncating is often used to completely remove all contents of a file, but it can also be used to limit a file to a specific maximum size. One notable characteristic of os.Truncate() is that it will actually increase the length of a file if it is smaller than the specified truncate limit. It will fill any blank space with null bytes.

Truncating a file has more practical uses than creating an empty file. When log files get too big, they can be truncated to save disk space. If you are attacking, you may want to truncate .bash_history and other log files to cover your tracks. Genuinely, malicious actors may truncate files just for the sake of destroying data. ...

Get Security with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.