Emptying a file on a GNU/Linux terminal.

Emptying a file on a GNU/Linux terminal

Miguel Menéndez Comments

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):

1$ > file-name

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

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

There are also other methods:

1$ cat /dev/null > file-name


1$ echo "" > file-name