I have a file called error.log on my server that I need to frequently truncate. I have rw permissions for the file. Opening the file in vi > deleting all content > saving wo
This will be enough to set the file size to 0:
> error.log
You can try also:
echo -n > /my/file
You can also use function truncate
$truncate -s0 yourfile
if permission denied, use sudo
$sudo truncate -s0 yourfile
Help/Manual: man truncate
tested on ubuntu Linux
I do like this:
cp /dev/null file
false|tee fileToTruncate
may work as well
Since sudo will not work with redirection >
, I like the tee
command for this purpose
echo "" | sudo tee fileName