How to create empty files from the command prompt (cmd)

How to create empty files from the command prompt (cmd): Well, sometimes you just need to create empty files in Windows for applications to work in a portable environment or to take advantage of the null files in another process. Whatever the reason might be, knowing how to create empty files from the command prompt will only be useful for you and will help you in understanding the system better.

touch command which creates empty files but in Windows, there is no such command that’s why it’s more important to learn how to create one. You must be thinking why not create an empty file from notepad and save it, well it doesn’t actually an empty file that’s why this task is accomplished by using the command prompt(cmd).

How to create empty files from the command prompt (cmd)

1.Press Windows Key + X then select Command Prompt (Admin).

2.Type the following command and hit Enter: cd “C:\Your Directory”
Note: Replace your directory with the actual directory you need to work with.

3.To create empty file just type this command & hit Enter: copy nul “emptyfile.txt”
Note: Replace emptyfile.txt with the name of the file you need.

4.If the above command fails to create an empty file then try this one: copy /b NUL EmptyFile.txt

5.Now the problem with above command is that it will always display that the file was copied and in order to avoid that you can also try the following command: type NUL > 1.txt

6.If you really want a totally empty file, without any output to stdout then you can redirect stdout to nul:
copy nul file.txt > nul

7.Another alternative is that run aaa> empty_file which will create an empty in the current directory and then it will try to run the command aaa which is not a valid command & in this way you will create an empty file.

8.Also, you could write your own touch command:

7.Save the above file as touch.cpp and that’s it you have created a touch program.

Recommended for you:

  • Fix dns_probe_finished_bad_config error
  • How to Fix Application Error 523
  • How to fix 502 Bad Gateway Error
  • Fix The application failed to initialize properly

That’s it you have successfully learned How to create empty files from the command prompt (cmd) but if you still have any queries regarding this guide then please feel free to ask them in the comment’s section.