If you want to clear contents of a file in unix, you could just delete the file and recreate it.
But there are much more simple alternatives.
You can use echo method.
To empty a file just enter the command below. I use my php_error.log file for example.
echo -n > /home/base/logs/php_error.log
That’s it. Your file is empty now.
You can use VI Editor.
First, open the file that you want to empty with vi editor. I use my php_error.log file for example.
vi /home/base/logs/php_error.log
On the first line, type “dG” without quotes. It means delete globally on VI Editor.
Then quit with “:wq” without quotes of course 🙂