Creating files is one of the most basic tasks while working with a computer. While most users rely on folders and right‑click options, the Command Prompt (CMD) offers a faster and more powerful way to create and manage files, especially for developers, system administrators, and anyone working on servers.
Using Command Prompt may look intimidating at first, but once you understand a few simple commands, it becomes easy and efficient. In this guide, we will walk you through step‑by‑step methods to create files using Command Prompt, explained in simple language so even beginners can follow along.
Before You Start
Before creating a file, make sure:
➔ You have opened Command Prompt.
➔ You are in the correct folder (directory) where you want to create the file.
Also Read: How to Check .NET Framework Version in Windows CMD?
How You Can Open Command Prompt?
➔ You have to press ‘Windows + R.’
➔ Type ‘cmd’ in the box.
➔ Press Enter
Step 1: Navigate to the Desired Folder
➔ Use the cd (change directory) command to move to the folder where you want to create the file.
Example:
| cd Desktop |
To check your current location, use:
| dir |
Also Read: How to Check Laravel Version in Windows CMD?
Methods to Create a File in Command Prompt
Method 1: Create a File Using the echo Command (Most Common)
The echo command is the most commonly used and beginner-friendly way to create a file in Command Prompt. This method is useful when you want to create a file and add content at the same time.
When you use echo, the text you type is written directly into the file. If the file does not exist, CMD automatically creates it. If the file already exists, its contents will be overwritten.
Syntax
| echo YourText > filename.extension |
Example
| echo Hello World > sample.txt |
What Happens Here?
➔ A new file named sample.txt is created.
➔ The text “Hello World” is written inside the file.
➔ If sample.txt already exists, its old content is overwritten.
When to Use This Method:
➔ When you want to quickly create a text file.
➔ When you want to add a single line of content.
➔ When working on scripts or configuration files.
Also Read: How to Check React Version in Windows CMD?
Method 2: Create an Empty File Using type nul
If you want to create a file without adding any content, the type nul method is the best option. This command creates a completely blank file.
This is especially useful when you need an empty file as a placeholder or want to add content later using another editor.
Syntax
| type nul > filename.extension |
Example:
| type nul > emptyfile.txt |
What Happens Here?
➔ CMD creates a file named emptyfile.txt.
➔ No text or data is added to the file.
➔ The file size remains 0 bytes.
When to Use This Method:
➔ When you only need an empty file.
➔ When preparing files for applications or servers.
➔ When you want full control over content later.
Also Read: How to Check the SQL Version in Windows CMD?
Method 3: Create a File Using the copy con Command
The copy con command lets you manually type content into a file from the Command Prompt. This method is interactive and lets you control what goes into the file.
Unlike the echo command, this method lets you add multiple lines of text before saving the file.
Syntax
| copy con filename.extension |
Example:
| copy con notes.txt |
Step-by-Step Process
➔ After entering the command, CMD waits for input.
➔ Type the content you want to save.
➔ Press Ctrl + Z to signal the end of the file.
➔ Press Enter to save the file.
What Happens Here?
➔ A file named notes.txt is created.
➔ All typed content is saved inside the file.
When to Use This Method:
➔ When you want to add multiple lines of text.
➔ When working without a text editor.
➔ For quick notes or configuration entries.
Also Read: How to Check Angular Version in Windows CMD?
Method 4: Create a File Using fsutil (Advanced)
The fsutil command is an advanced tool for creating files with a specific size. This command is mostly used for testing, storage allocation, or system-level tasks.
Unlike other methods, this does not add readable text. It simply creates a file with the defined size in bytes.
Syntax
| fsutil file createnew filename.extension size_in_bytes |
Example:
| fsutil file createnew test.txt 1024 |
What Happens Here?
➔ A file named test.txt is created.
➔ The file size is exactly 1024 bytes (1 KB).
➔ The file contains no readable text.
Important Note
➔ Command Prompt must be opened as Administrator.
➔ This method is not meant for normal text files.
When to Use This Method:
➔ For testing disk space.
➔ For system or server-level operations.
➔ When file size matters more than content.
Also Read: How to Check Folder Permission in Windows CMD?
Verify the File Creation
After creating the file, use:
| dir |
This command lists all files in the current directory so you can confirm your file exists.
Common Errors & Tips
➔ Access Denied: Run Command Prompt as Administrator
➔ Wrong Directory: Always check your location using dir
➔ File Overwritten: Use >> instead of > to append content
Example (Append Text):
| echo New Line >> sample.txt |
Conclusion
Creating files using Command Prompt is a simple yet powerful skill. Whether you want to create a blank file, add quick content, or generate files for development and server tasks, CMD gives you full control with just a few commands.
Once you get comfortable with these methods, you will find Command Prompt faster than traditional file creation for sure, especially when managing multiple files or working on hosting servers. Start practicing these commands, and Command Prompt will soon feel like a helpful tool rather than a complicated one.
Happy Commanding!
