What is the best way to create an empty file from the command line in windows?

I have been using the touch command but it isn't in stock windows.

One idea was to use echo . >file that works, but the file is never really empty that way. Is there a way to generate an empty file similar to what touch file would do using only what comes with stock windows.

3 Answers 3


From this answer on Stack Overflow

type nul >file
echo. 2> file

Give that one a try

  • +1 Don't know who marked this down as it does work
    – Linker3000
    Apr 19, 2011 at 22:29
  • 1
    +1: Because I learned something, and this is a cool hack. :) Apr 19, 2011 at 23:25
  • You can use any command, so if you wanted to make it even shorter how about: cd 2> file :)
    – Gaff
    Apr 20, 2011 at 6:09
  • 1
    No, I was pointing out that this doesn't depend on echo at all, you can use any command (in this case I chose 'cd' because it's so short in length) so long as it doesn't output to the standard error stream (i.e. 2>). You'll basically be writing nothing to 'file'.
    – Gaff
    Apr 20, 2011 at 12:52
  • 1
    You can use any command, @8088, not any command, only commands which do not output anything to stderr. For example, try ren 2> file.
    – Synetech
    Sep 15, 2015 at 0:56
copy con file [Enter]
[F6] (or [Ctrl-Z]) [Enter]


  • copy nul file ....
    – Joshua
    Dec 3, 2015 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.