How to clear contents of a file?

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
  • 92 Els usuaris han Trobat Això Útil
Ha estat útil la resposta?

Articles Relacionats

Setting time with NTP in LINUX

NTP (Network Time Protocol) could be used to set time synced with ntp clocks, to do this use the...

Linux version & Operating System info

LINUX Version Info To learn the architecture and kernel version info use the shell command...

Compile and build Apache + MySQL + PHP from the source [cite]

This is a complete working solution to build Apache (httpd-2.2.25), MySQL (MySQL-5.6.14) and PHP...

Using vi Editor

Vi is the one of the mostly used editor in Linux via terminal. In most cases where Linux is used...

Build PHP5.5 on CentOS 6.4 with MSSQL Support [cite]

Most of the yum repos doesn’t include PHP5.5.X on current releases for the time being. So...