There are many ways to create an empty text file from command line. This post shows 3 ways.
To create empty file from Linux command line, you can use one of the following methods:
1. touch filename
2. vi filename and close file
3. echo > filename
touch is a tool that comes packaged with Linux. It is often used to check if you have permissions to a certain file or directory. It can also be used to create a file. Suppose you want to create a file called events.txt:
touch events.txt
That’s it. If you have permissions to create a file in that location, an empty events.txt is created.
vi editor can also be used to create events.txt as follows:
$ vi newfile
If you have permissions to create a file in that location, an empty events.txt is created.Then press Esc key followed by :wq. and an empty file would be created.
echo can be used to create events.txt as follows:
$ echo > newfile.txt