Truncating a file?
To truncate a file is to make it empty (its size becomes 0 byte). This comes in handy for logs, when they grow too big, or when you need to re-use an existing file but want to skip the chmod/chown steps.
So, how to truncate a file?
Just enter and execute the following (replacing “filename.ext” with the actual name of the file you want to truncate):
Its size should now be zero, unless…
sudo sh -c ">filename.ext"
Enter your password if asked, and now its size should be zero.
If you are not in the sudoers list, then too bad, you cannot truncate this file.
Know of another / a better way to truncate file?
Please share it!