Windows OS

How to Create an Empty File Using Windows Command Line

A file is a basic component of the system, and it can store textual data, images, program scripts, binary, and many others. A simple text file is stored with a .txt extension, while the program file can be stored with an extension depending on programs such as .html to store HTML and .py to store Python code. An empty file indicates that it has no content and the size will be “0” byte.

We will elaborate on the ways to create an empty file through the Windows Command Line in this blog:

So, let’s get started!

Use Command Prompt to Create Empty File on Windows

To create an empty file using the command line on Windows, you can utilize the below-listed commands:

  1. cd.
  2. echo.
  3. call
  4. break
  5. copy nul
  6. type nul

We will discuss each of them one by one.

Method 1: Use “cd.” Command to Create Empty File

Check out the method provided below to learn how to create an empty file using the “cd.” command.

Step 1: Open Command Prompt

First, search for “Command Prompt” in the “Startup” menu and open Command Prompt as administrator:

Step 2: Open Directory

In the next step, specify the path in the “cd” command to open the preferred directory where you want to create and save an empty file:

>cd C:\Users\anuma\OneDrive\Documents

Step 3: Create an Empty File Using “cd.” Command

Utilize the “cd. ” command and redirect “>” its output to an empty file. After creating the file, use the “dir” command the verify the existence of the created empty file:

>cd. > File1.txt

>dir

Method 2: Create an Empty File Using “echo.” Command

To create the empty file, run the “echo. >” command and redirect “>” the output to the new empty file. Then validate the performed operation with the “dir” command:

>echo. > File2.txt

>dir

Method 3: Create Empty File Using “call” Command

Empty file can also be created through the “call” command. For this purpose, follow the provided command:

>call > File3.txt

>dir

Method 4: Create Empty File Using “break” Command

To create an empty file on Windows Command Prompt, the “break” command can also be used. After that, execute the “dir” command to list all files and confirm whether the empty file is created or not:

>break > File4.txt

>dir

Method 5: Create Empty File Using “copy nul” Command

To create the empty file on Windows using “copy nul”, write out the below-given command:

>copy nul "Newfile.txt"

After creating the file, utilize the “dir” command to view a list of files for the confirmation purpose:

>dir

Method 6: Create Empty File Using “type nul” Command

In order to create the empty file on Windows using the command line, you can use the “type nul” command on Command Prompt as shown below:

>type nul > File.txt

Then, utilize “dir” command to view a list of files to confirm whether the file is created or not:

>dir

We have successfully demonstrated the methods used to create an empty file in Windows Command Prompt.

Use PowerShell to Create Empty File on Windows

In order to create an empty file on Windows, you can use the “New-Item” command on PowerShell. Follow the below-given instructions to create empty file.

Step 1: Open PowerShell

Firstly, press “Window+X” to access the Power User menu. Then, open the Windows PowerShell as administrator:

Step 2: Create New Empty File on a Specific Location

Create an empty file using the “New-Item” command and add the path where the file will be saved. The last portion of the path will be considered as file name:

> New-Item C:\Users\anuma\OneDrive\Desktop\Create_EmptyFiles\samplefile.txt

Or simply execute the given command for creating an empty file in the current directory:

> New-Item samplefile1.txt

From the below-given output, you can see that we have successfully created the “samplefile1.txt” empty file:

We have effectively compiled the solutions to create an empty file on Windows.

Conclusion

To create an empty file on the Windows Command line, you can utilize Command Prompt or PowerShell. On Command Prompt, many commands are available to create a new file or empty file, such as “cd.”, “copy nul”, ”break”, “echo.”, “type nul”, and “call”. In Windows PowerShell, the “New-Item” command can be executed for the same purpose. We have illustrated the methods to create empty files on the Windows command line.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.