In the following snap code I’ll show you how to empty a file from the command line in Linux or Mac OS. This without any need for opening the file self or deleting it and creating a new one with the same name.

Let say that you have a file called emptyme.txt. To empty the content of this file just use the following command and it’s done:

1
$ > emptyme.txt

This will empty the content of emptyme.txt

1
$ cat /dev/null > emptyme.txt

This will read the content of /dev/null (which contains in fact nothing) and > write this into emptyme.txt

1
$ echo "Hello there!" > emptyme.txt

This will empty the content of emptyme.txt and drop the “Hello there!” string it in it.