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.

Now PSIX-compatible systems have 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.

C:\Users\Aditya>cd Desktop C:\Users\Aditya\Desktop>aaa >empty_file 'aaa' is not recognized as an internal or external command, operable program or batch file. C:\Users\Aditya\Desktop>dir Direcotory of :\Users\Aditya\Desktop 09/06/2017 10:41

. 09/06/2017 10:41

.. 09/06/2017 10:41 0 empty_file

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

#include #include int main(int argc, char ** argv;) { if(argc !=2) { std::cerr << "Must supply a filename" << endl; return 1; } std::ofstream foo(argv[1]); foo.close(); return 0; }

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

Recommended for you:

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.

Leave a Comment

What Young Riders Should Know About Moving Their Motorcycles Across Cities

What Young Riders Should Know About Moving Their Motorcycles Across Cities

Long-distance travel can involve heavy traffic, changing weather conditions, and rider fatigue. If you are also dealing with the responsibilities of moving home, such as packing belongings or coordinating accommodation, a long ride may add unnecessary pressure to an already busy schedule.

Solving Microsoft Teams Shortcut Error Not Opening

Solving Microsoft Teams Shortcut Error Not Opening

Tired of Microsoft Teams shortcut error preventing you from opening the app? Follow our expert, step-by-step guide with the latest fixes for instant resolution. Works on Windows, Mac &amp; web – no tech skills needed!

Solving Microsoft Teams Task Management Sync Error

Solving Microsoft Teams Task Management Sync Error

Tired of Microsoft Teams Task Management Sync Error halting your workflow? Follow our proven, step-by-step fixes to resolve sync issues fast and restore seamless task collaboration. No tech expertise needed!

Troubleshooting Microsoft Teams Wiki Error Formatting

Troubleshooting Microsoft Teams Wiki Error Formatting

Struggling with Microsoft Teams Wiki Error Formatting? This step-by-step guide reveals proven fixes for common wiki tab issues, ensuring smooth editing and collaboration in Teams. Get back to productive wikis fast!

How to Fix Microsoft Teams Installation Error for Linux

How to Fix Microsoft Teams Installation Error for Linux

Struggling with Microsoft Teams installation error on Linux? Discover step-by-step fixes for Ubuntu, Fedora & more. Resolve dependency issues, crashes, and errors quickly with our ultimate guide. Get Teams running smoothly today!

Solving Microsoft Teams Error Page Not Loading

Solving Microsoft Teams Error Page Not Loading

Struggling with Microsoft Teams "Error Page" not loading? Get step-by-step fixes for desktop, web, and mobile. Solve Microsoft Teams Error Page issues quickly and resume seamless teamwork today.

Solving Microsoft Teams Error Screenshot Issues

Solving Microsoft Teams Error Screenshot Issues

Tired of Microsoft Teams "Error Screenshot" blocking your workflow? Get proven, step-by-step solutions to resolve screenshot errors in Teams instantly and boost productivity. No tech skills needed!

How to Fix Microsoft Teams Error U User

How to Fix Microsoft Teams Error U User

Tired of Microsoft Teams "Error U" User blocking your chats? Get proven, step-by-step fixes to clear cache, reset, and restore seamless collaboration instantly.

Where are Microsoft Teams Registry Keys Located on Windows 11?

Where are Microsoft Teams Registry Keys Located on Windows 11?

Unlock the precise locations of Microsoft Teams registry keys on Windows 11. Step-by-step guide to find, access, and safely tweak them for optimal performance and troubleshooting. Essential for IT pros and Teams enthusiasts.

How to Fix Microsoft Teams Training Error Video Lag

How to Fix Microsoft Teams Training Error Video Lag

Tired of Microsoft Teams "Training Error" Video Lag ruining your meetings? Follow our step-by-step guide with the latest fixes for smooth video calls—no more frustration!