Home » How to Create a File in CMD

How to Create a File in CMD

You can use the following syntax in Command Prompt (CMD) to create a new file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
echo. > filename
echo. > filename
echo. > filename

In this example, it will create an empty file with the specified name in the current directory.

Alternatively, you can use the type nul command to create an empty file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
type nul > filename
type nul > filename
type nul > filename

The following example shows how to use this syntax in practice.

Example: Create a File in CMD

Suppose that we want to create a new file named test.txt in the following directory:

C:\Users\admin\Documents\cmd_script

We can type the following command to create the file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
echo. > C:\Users\admin\Documents\cmd_script\test.txt
echo. > C:\Users\admin\Documents\cmd_script\test.txt
echo. > C:\Users\admin\Documents\cmd_script\test.txt

Output: 👇

CMD - Create a file
CMD – Create a file

We can see that the file test.txt has been created in C:\Users\admin\Documents\cmd_script\.

Alternatively, we can use the type nul command:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
type nul > C:\Users\admin\Documents\cmd_script\test.txt
type nul > C:\Users\admin\Documents\cmd_script\test.txt
type nul > C:\Users\admin\Documents\cmd_script\test.txt

Output: 👇

CMD - Create a file using type nul
CMD – Create a file using type nul

We can see that the file test.txt has been created in C:\Users\admin\Documents\cmd_script.

Conclusion

You can use the echo. or type nul command followed by the path and filename to create a new file in any directory on your system.

You can find more topics about Active Directory tools and PowerShell basics on the ActiveDirectoryTools home page.