Clear contents of a file
Posted on 2007-03-28
Let's say that I have a Java program running, with its standard output directed to a log file:
java MyJavaProgram > stdout.log
This program will keep on running. To ensure that the log file does not grow very big, I am trying to write a script to remove the contents of the file. I tried two ways:
echo "" > stdout.log
cp /dev/null stdout.log
But in both cases, they are writting a lot of null characters into the log file. The file does not shrink at all. The contents are merely replaced with null characters.
How can I achive what I want? Thanks.