Creating an empty file is an important concept to manage the record before writing data in it. It occupies 0 bytes because no data is stored in it. If you are at the beginner stage of Linux user and don’t know the creation of empty files for storing data or information. This guide will demonstrate several methods to create an empty file in the Ubuntu system. The supported content is enlisted below:
- Method 1: Create an Empty File Using the “touch” Command
- Method 2: Create an Empty File Using the “echo” Command
- Method 3: Create an Empty File Using Nano Editor
- Method 4: Create an Empty File Using “printf” Command
- Bonus Tip: How to Check the Status of an Empty File?
Method 1: Create an Empty File Using the “touch” Command
In Linux, most administrators need to create empty files to manage multiple files with the name of network users. The “touch” command helps to create an empty file by specifying the name based on needs. To create an empty file, run the below script:
$ touch firstfile.txt
Using the “ls” command, you can verify that “firstfile.txt” has been created in the Home directory:
Method 2: Create an Empty File Using the “echo” Command
An alternative method for creating an empty file is possible through the “echo” command. This command requires the “-n” utility to create an empty file specifying the name and file type.
$ echo -n > office.txt
To confirm the creation of the empty file, you can utilize the “ls” command to visualize the “office.txt” has been successfully created in the directory.
Method 3: Create an Empty File Using Nano Editor
Another method can be considered to generate an empty file via Nano Editor. For instance, the “officefile.txt” file has been created through the “nano” command:
$ nano officefile.txt
After executing the above command, it navigates to the Nano Editor by specifying the particular file name.
The empty file is ready, as visualized in the above figure.
Method 4: Create an Empty File Using “printf” Command
An interesting method can also be adapted for creating an empty file through the “printf” command. For this purpose, an “empfile.txt” will be created after executing the below script:
$ printf ' ' > empfile.txt
After executing the script, the “empfile.txt” has been created that can be visualized via the “ls” command:
That is all for creating an empty file.
Bonus Tip: How to Check the Status of an Empty File?
It is additional information to display the status of an empty file. In our case, an existing file, “firstfile.txt”, is stored in the home directory. To check the status of the particular file, run the below script:
$ file firstfile.txt
The executed command verifies the status “empty” of the particular file “firstfile.txt” in the above figure.
In Ubuntu, the “touch”, “echo”, “nano”, and “printf” commands are used to create an empty file in the home directory. These above commands require the file name and type users want to create. These empty files can be modified through the Nano Editor. Also, users can find out the file status by executing the “<file filename.txt>” script. This guide has explained all possible methods for creating an empty file via the Ubuntu terminal.