Emptying a file on a GNU/Linux terminal.

Emptying a file on a GNU/Linux terminal

Miguel Menéndez

Sometimes it is necessary to empty plain text files quickly and without complications from the command line on a local machine or remotely via SSH.

As fast and intuitive (although, if we’re not careful, dangerous):

~$ > file-name

For example, to clear a error log file after having solved all the problems that generated it:

~# > /var/log/apache/error.log

There are also other methods:

~$ cat /dev/null > file-name


~$ echo "" > file-name