Last Updated :
07 Apr, 2025
We all know that one can easily create files using GUI options, but what if you can use a faster way to create files through the command-line interface? This is not a necessary but useful skill for anyone working with Windows. Whether you’re automating tasks, working on scripts, or preferring using the command prompt, knowing how to create a file in CMD can be incredibly useful.
This article will walk you through the steps to create a file using CMD, ensuring that you can efficiently manage your files directly from the command prompt.
Methods to Create A File on Windows using CMD
To start a new file on Windows using CMD, the following guidelines should be used. Let us start with the basic Echo Command.
Note: All of these methods should be executed in any certain directory. Otherwise, the operations will not completed. Use the CD Windows Command to enter into any certain Windows directory.
Method 1: Create Text File Using ECHO in Command Prompt
Step 1: Open CMD
- To create a file using CMD open CMD press Win + R key on your keyboard and type CMD to open CMD.
Step 2: Type ECHO Command
- Once the CMD opens execute the following command.
This method will directly save the file to the directory mentioned earlier. You have to put some text for it.
Command: echo. > Rapture.txt
Congratulation! The New Text File on Windows is created using the Command Prompt with one simple command.
Method 2: COPY CON Command to Create a New File
Step 1: Use copy con in CMD
- You need to type «copy con» followed by the name of the file you wish to overwrite and once you’re done press the CTRL + Z to end the operation & the file will be directly saved to the directory.
Let’s understand this with the below-mentioned example where the file name = ‘Rapture’
Command: copy con Rapture.txt
Hooray! We have successfully created a Text File on Command Prompt on Windows in a certain directory without opening it.
Method 3: Quick Guide to Create a File in CMD — NOTEPAD Command
The following command can be used to open any Text File. Either, you can open the New File with any predefined name or any existing one in the certain directory. It will open the Notepad Windows Application, make changes there & press CTRL + S to save it.
Command: notepad Rapture.txt
Method 4: ‘fsutil’ Command to create a «specific» size file
The following command can be used to create a file in CMD for any specific size. Once you create the file, you do perform tasks accordingly.
For example: Let’s create a file of size 10 bytes with the filename as ‘Rapture’
Command: fsutil file createnew Rapture.txt 10
Method 5: «type nul» Command to create a new File
The type nul command in cmd can be used to create a new file wherein the «type nul» denotes to do nothing and starts with an empty file. Let’s understand this with an example below where the filename is ‘Rapture’.
Command: type nul >Rapture.txt
Conclusion
Mastering the ability to create a file in CMD is an essential part of becoming proficient with the command line in Windows. By using the right CMD command to create a file, you can streamline your workflow and perform tasks more efficiently. Whether you’re creating simple text files or working on more complex scripts, understanding how to make a file in CMD gives you greater control over your system.
Also Read
- Most Useful CMD Commands in Windows
- CMD Commands to Gather Information of a System
- How to Show all the previously connected WiFi Networks using CMD in Windows?
Empty files are those with a file size of zero bytes and no data stored in them. You can make an empty text file, word document, or whatever you want.
With the «touch» command in Linux, we can easily create an empty file. In Windows OS, there is no direct equivalent command for touch. But don’t worry, you can accomplish the same thing using a variety of methods in Windows, which I will go over in detail.
Table of Contents
- 1 Using Echo Command in Command Prompt or Batch File
- 2 Using Copy Command in the Command Prompt or Batch File
- 3 Using winit in Command Prompt or Batch File
- 4 Using REM in Command Prompt or Batch File
- 5 Using Powershell
- 6 Using Type Operator in Command Prompt or Batch File
- 7 Using fsutil Command in Command Prompt or Batch File
- 8 Using Colon Operator in Command Prompt / Batch File
- 9 Using Call Operator in Command Prompt / Batch File
- 10 Using break command in command prompt / Batch File
- 11 Using echo with caret(^) in command prompt / Batch File
- 12 Using «type con» command in Command Prompt / Batch File
In general, we like to create a dummy file just for testing our application and then add the information as needed later. You can create an Empty File with the GUI, Command Prompt, or Powershell.
1 Using Echo Command in Command Prompt or Batch File
The echo command in Windows is used to display a string provided by the user. We can create an empty file using Echo and let’s look at the syntax at first.
Here you have to understand follow points:
— No need for administrative privileges.
— In this method, if the file already exists then also it will overwrite the file and create the new one.
1a) Method 1
Syntax:
echo -n "" > filenamewithpath
Where «filenamewithpath» indicates you create a filename with a path mentioned in it.
Example:
echo -n "" > D:\empty.txt
Inside D drive, I’m making an empty.txt file.
> is a redirection operator, and is used to send whatever is ever-present on the left to the right. Here echo is holding an empty string «» and an empty string is written to the file empty.txt.This empty string will have 0 sizes.
You can replace D:\empty.txt with whatever you like.
Note that if you are going to write in C drive (or any drive where windows is installed) then you may get access denied.
1b) Method2
Combining echo on/off with & operator
echo off > D:\empty.txt & echo on
1c) Method 3
echo. 2>"D:\empty.txt"
2 Using Copy Command in the Command Prompt or Batch File
The Copy command in Windows is typically used to copy one or more files from one location to another. They can be used to create files, empty files, and so on.
Notes:
- No need for administrative privileges.
- In this method, if the file already exists then also it will overwrite the file and create the new one.
Example:
COPY NUL "D:/empty.txt" > NUL
If the file does not exist, the copy will create a new one; if it does exist, it will overwrite the previous one.
In this case, we’re copying NUL to the empty.txt file, and the «> NUL» indicates that it will not display any success or failure messages like «1 file(s) copied.» or «Overwrite asdddff.txt? (Yes/No/All):»
3 Using winit in Command Prompt or Batch File
wininit is a Microsoft Windows operating system software component. Using winit.exe, we can create an empty file.
Notes:
- No need for administrative privileges.
- In this method, if the file already exists then also it will overwrite the file and create the new one.
Example:
wininit >D:\empty.txt
4 Using REM in Command Prompt or Batch File
REM is an abbreviation for Remark. It supports the inclusion of comments within batch files. REM can be used to create the empty file shown below.
Notes:
- No need for administrative privileges.
- In this method, if the file already exists then also it will overwrite the file and create the new one.
Example:
REM. >D:\empty.txt
5 Using Powershell
Microsoft Powershell is a set of task automation and configuration management tools. We can use this tool to create an empty file. Simply launch PowerShell and enter the following:
Example:
New-Item D:\empty.txt
Just replace empty.txt with whatever you want.
6 Using Type Operator in Command Prompt or Batch File
type is an in-built command that displays the contents of a text file.
Notes:
- No need for administrative privileges.
- In this method, if the file already exists then also it will overwrite the file and create the new one.
Example:
type NUL > D:\empty.txt
7 Using fsutil Command in Command Prompt or Batch File
Notes:
- Need for administrative privileges.
- In this method, if the file already exists then it doesn’t overwrite the file and will prompt you with an error like «Error: The file exists.» if you include «< nul» in the command then it will not prompt a message.
Example:
fsutil file createnew D:\empty1.txt 0 > nul
8 Using Colon Operator in Command Prompt / Batch File
Example:
: > D:\empty.txt
9 Using Call Operator in Command Prompt / Batch File
You can make an empty file using the Windows command line by combining the «call» method with the «echo» command and the redirection operator. This will allow you to create an empty file.
First, navigate to the path where you want to create an empty file, and then type the following command.
call echo. > filename.txt
Simply change «filename.txt» to the name you want to assign the empty file and hit the «Enter» button.
10 Using break command in command prompt / Batch File
The syntax for it is as follows
break > filename.txt
Simply change «filename.txt» to the name you want to assign the empty file and hit the «Enter» button.
This command redirects the «break» command’s null character output to the given filename. This command makes the file in the current directory like the others.
11 Using echo with caret(^) in command prompt / Batch File
The syntax for this is as follows:
echo ^ > filename.txt
Simply change «filename.txt» to the name you want to assign the empty file and hit the «Enter» button.
12 Using «type con» command in Command Prompt / Batch File
The syntax for it is as follows:
type con > filename.txt
FAQ:
How to create read-only empty files in Windows?
We can easily create read-only and empty files in Windows by combining two texts one creates an empty text file and then set read-only permission to the file.»type Nul > abc.txt» creates an empty file and «attrib +r abc.txt» creates read-only permission for the same file. Here, attrib is used to set and remove file attributes like hidden(h), read-only(r), system(s), and archive(a).
type Nul > abc.txt & attrib +r abc.txt
If you want to remove read-only from this you can use the «-r» parameter instead of «+r»
How to create a hidden empty file in Windows?
For this we use «+h» parameter as shown below.
type Nul > abc.txt & attrib +h abc.txt
How to create multiple empty files in Windows?
For creating multiple we can use for loop to generate the empty file. Here we are creating 10 empty files in the current location. The filename will be respectively:myemptyfile-1.txt,myemptyfile-2.txt,myemptyfile-3.txt and soon up to myemptyfile-10.txt
for /l %a in (1 1 10) do type nul > "myemptyfile-%a.txt"
Can we create Empty doc, xlsx files in Windows?
Yes, you can create empty docs, and xlsx files using any of the above methods. You can simply try this:
type NUL > D:\emptyDocsFile.docx
Conclusion:
With the aforementioned methods, we can successfully create empty files such as txt, Docx, xlsx, or any text file.
cmd Creating files
Creating files in the Windows Command Prompt (cmd) can be done using several different commands. Below, I’ll explain some common methods for creating files, along with examples for each method.
Methods for Creating Files in cmd
-
Using the
echo
Command- The
echo
command is often used to display messages, but it can also create files by redirecting output to a file.
Basic Syntax:
Example:
To create a file namedexample.txt
and write «Hello, World!» into it:Output:
This command creates a file called
example.txt
in the current directory containing the text «Hello, World!».- Creating an Empty File:
If you want to create an empty file:
- The
-
Using the
type nul
Command- The
type
command can also be used withnul
to create an empty file.
Example:
To create an empty file namedemptyfile.txt
:Output:
This command creates an empty file called
emptyfile.txt
. - The
-
Using the
copy con
Command- The
copy con
command allows you to create a file and input text directly from the command prompt.
Basic Syntax:
Example:
To create a file namednote.txt
:After running this command, you can type your text. Once finished, press
Ctrl + Z
and thenEnter
to save the file.Output:
Type your text here. After pressing
Ctrl + Z
, the command prompt will indicate that the file has been created: - The
-
Using the
fsutil
Command- The
fsutil
command can be used to create files, but it is more advanced and typically used for file system management.
Basic Syntax:
Example:
To create an empty file namedlargefile.txt
of size 1 MB:Output:
This command creates a file named
largefile.txt
with a size of 1 MB. - The
-
Using the
notepad
Command- You can also create a file using Notepad from the command prompt. This is useful for creating and editing files directly.
Basic Syntax:
Example:
To create or open a file namedmyfile.txt
in Notepad:Output:
This command will open Notepad, allowing you to enter text and save the file.
Summary
Creating files in the Windows Command Prompt can be done through various methods, including using echo
, type nul
, copy con
, fsutil
, and even opening Notepad. Each method serves different purposes, from creating empty files to directly inputting text. Mastering these commands can enhance your efficiency in managing files and automating tasks within the command-line environment.
Wondering how to create a file using Command Prompt on Windows computers? This article will guide you on how you can easily do that.
We often find the need to create files and folders on our Windows computers to store various data types such as text, images, programs, and more.
While the Windows Graphical User Interface offers a user-friendly approach to do that, there are cases when using the Command Line Interface, specifically the Command Prompt, becomes essential.
Meanwhile, using the Command prompt to create a file on a Windows computer is equally uncomplicated. In the following sections, we will discuss how to create a file using Command Prompt on Windows PCs effortlessly.
Table Of Contents
- How to Create a File With Command Prompt on Windows?
- Method 1. Create an Empty File Using Command Prompt
- Method 2. Creating a File Containing Certain Text
- Method 3. Creating a file of a certain size
- Method 4. Creating Multiple Files
- Wrap Up
How to Create a File With Command Prompt on Windows?
If, for any specific reason, you aim to create a file via Command Prompt on Windows, there are several approaches at your disposal.
Before initiating the file creation process with the Command Prompt — even if you are using File Explorer — it is necessary to navigate or move to the directory where you intend to keep the file.
Say you intend to create a file in the Desktop directory/folder, you need to navigate to the Desktop folder on your computer. When using Command Prompt, it initially opens to the User directory level.
Hence, you can switch to the Desktop folder, a subfolder of the User directory, by using the cd (change directory) command. This can be done by following these steps:
1. Press Windows + R to open the Run Command Box.
2. Type cmd in the box and hit Enter.
3. In the Command Prompt window, type cd Desktop and hit Enter to move to the Desktop folder. Immediately, you will have Desktop before the text cursor in the command prompt page showing that any command you will be running to create a file on the PC will be creating the file in the Desktop folder.
You can navigate to different folders using the command “cd folder name,” where the “folder name” part should be the name of the subfolder you wish to access and create a file in.
Additionally, to move to the directory where you want to save a new file, use the command “cd directory path
.” For instance, you can type “cd C:\Users\Public\Pictures
” to create a file in the CMD within the Pictures folder of the path used.
In a case when you want to create a new directory under your current directory level, you can do that by using the command below
mkdir directory_name
For example, to make a new folder/directory named MyFolder within the Desktop directory, enter the command mkdir MyFolder
.
Subsequently, if you want to create a file using Command Prompt in this new folder, simply type cd new_directory_name
. The command to be used in the case of our example above is cd MyFolder
.
Note: You also can view the directories or folders within the current or opened directory level in the command prompt by executing the following command. Type dir in the command prompt and hit enter.
Having navigated to the directory you intend to store the file you wish to create, here are the potential methods to create a file using Command Prompt on Windows, according to your preferences:
Method 1. Create an Empty File Using Command Prompt
Command Prompt allows Windows users to effortlessly create an empty file of various types, such as png for images, docx for Word documents, txt for text files, and more. This command automatically produces the file in your present directory.
To create an empty file on your Windows PC using Command Prompt, input the following command and hit Enter:
type nul > filename.extension
Suppose I aim to create an empty Word document file named “EmptyDocs” at the Desktop directory level on my PC using Command Prompt. In that case, I would input the following command and press Enter:
type nul > EmptyDocs.docx
Therefore, the final part of the command – extension — will rely on the file format of the file you are creating.
Note: You can open the file created to confirm the method by entering filename.extension
and pressing Enter.
CURRENT DIRECTORY LEVEL IMAGE
Method 2. Creating a File Containing Certain Text
Another capability of the Command Prompt on Windows for file creation involves creating a file with specific text. This method is tailored for creating text files and includes the ability to input text directly through the command prompt, unlike the first method mentioned above, which only permits the creation of an empty file.
There are two commands you can use for this method and here are they:
echo command
The echo command primarily showcases the text you input in the Command Prompt. However, it can also serve to generate a text file on Windows PCs, echoing the text entered with the command into the created file.
To use this command to create a text file with certain text, enter the following command and hit Enter:
echo the_text_to_input_in_the_file > filename.extension
For example, if you want to create a text file with the text “Thank you, Techworm”, simply enter the command below and hit Enter:
echo Thank you, Techworm > hello.txt
copy con command
Rather than using the echo command, an alternative method you can use is the copy con command. This also creates a text file with specific content on your PC. This process, however, follows a distinct sequence where you input the command first, run it, and then type the desired text into the file.
To employ the copy con command, initiate the text file creation and naming by entering the command below and pressing the Enter key:
copy con MyFile.txt
After that, type the text to be input in the file, press Ctrl + Z, then press Enter.
Your file will immediately be created in your current directory level.
Method 3. Creating a file of a certain size
You can easily create a file of a specific size using Command Prompt on Windows. This is a straightforward process and can be useful in various scenarios.
Just input the following command and press Enter:
fsutil file createnew filename.txt 1000
In the command, insert your desired file name in place of “filename,” while the digit at the end represents the file size in bytes.
Method 4. Creating Multiple Files
You can create multiple files in a folder at once by using the for loop command. This approach saves you the effort of manually creating numerous files with the same format one-by-one. This method can be used by entering the command below in your Command Prompt and pressing Enter:
for /l %a in (1 1 5) do type nul > "%a.txt"
This method uses the “type nul” command, as explained as the initial method in this article, enabling the creation of empty files in any format.
The (1 1 5) in the command instructs to create multiple files sequentially from 1 to 5 with an incremental step of 1. To generate a different number of files, such as 10, you would need to substitute the 5 with 10, adjusting accordingly for other quantities.
Also, the presence of .txt at the end of the command signifies the creation of text files. In a different scenario, such as wanting to create Word files, the command would need to be adjusted to::
for /l %a in (1 1 5) do type nul > "%a.docx"
The file created by this command will be saved in the directory where the command is executed.
In addition, you can assign a shared filename to multiple files rather than solely numbering them. You can do this by entering the following command and pressing Enter:
for /l %a in (1 1 5) do type nul > "filename %a.txt"
If you aim to name the files as TextFile-1, TextFile-2, and so on, the command to use would be:
for /l %a in (1 1 5) do type nul > "TextFile- %a.txt"
There you have it—five text files generated with just one command.
Wrap Up
The methods we covered above are some of the options for creating a file with Command Prompt on Windows. You can utilize any of the methods based on what you want to accomplish.
Additionally, you can delete files on your Windows PC using the Command Prompt as long as the file is under your current directory level. To do this, simply type Del filename.extension and press Enter.
Luqman
A tech junkie, and music fan.
I love writing Reviews, How-to, and explainer articles related to Android, iOS, and Windows. If I’m not on my laptop brainstorming ideas for content, you’ll most probably see me watching Tv shows or streaming videos on Youtube. Don’t forget to follow me on Twitter as @Luqqman14
Sometimes you have a bat script or you are just working in cmd and you need to create an empty file. Maybe as a placeholder for something or you want to create a file and append text to it later on. but how do you create a file in CMD?
There are multiple options to create an empty file or a file with text in command. In this article, we are going to look at the different options.
Creating a file in command is basically done by redirecting some form of output to a file. Redirecting output is done with the >
operator. This means that we can, for example, redirect the text “test” to a new file with the following command:
echo test > filewithtext.txt
This creates a new text file, named filewithtext.txt with the word test in it.
Creating an Empty File in Command
It’s also possible to create an empty file in command. To do this we will be redirecting a NUL value to a new file. This way a new file is created with nothing in it. There are two ways to do this, we can copy the value of NUL to a new file. Or we can use the TYPE command, which will get the contents from a file, in this case, NUL, and redirect it to a new file.
copy NUL EmptyFile.txt
Note that we are not using the redirect operator here. The copy command file copy the contents from the NUL command to the file EmptyFile.txt. If the file doesn’t exist, it will be created.
The other option is to use the TYPE command:
type nul > emptyfile.txt
The command Type will open the contents of the given file in the command prompt, in this case, NUL
, and the redirect operator >
will redirect the results to the file emptyfile.txt.
There is even a shorter method to create a new empty file, but I don’t like to use it. The problem is that it will throw an error. The error can be ignored, the result is an empty file:
. > empty.txt
Create a File and open it
Besides just creating a new file, it’s also possible to create a new file and open it. This allows you to add text to it immediately. To do this we will be using the built-in notepad command:
notepad newfile.txt
This method also works for some other applications, for example, if you have Visual Studio installed, you can use the command code
followed by the file name to create and open a new file.
Wrapping Up
Creating a new file in command is pretty straightforward as you can see. To create an empty file we basically redirect a null output to a new file.
I hope this article helped you create a new file, if you have any questions, just drop a comment below.