Low Orbit Flux Logo 2 F

Linux How To Empty Or Truncate A File

It is easy to truncate or empty a file from the command line on Linux

You can echo an empty string to the file that you want to truncate like this.

echo > test.log

You can also just use the redirection operator by itself like this.

> test.log

There also exists a truncate command which allows you to truncate a file to whatever size you want. In this case we are setting the size to zero which will effectively empty the file.

truncate -s 0 test.log