7

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

11

From this answer on Stack Overflow

type nul >file
6
echo. 2> file

Give that one a try

6
  • +1 Don't know who marked this down as it does work
    – Linker3000
    Commented Apr 19, 2011 at 22:29
  • 1
    +1: Because I learned something, and this is a cool hack. :) Commented 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 :)
    – Gareth
    Commented 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'.
    – Gareth
    Commented 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
    Commented Sep 15, 2015 at 0:56
3
copy con file [Enter]
[F6] (or [Ctrl-Z]) [Enter]

:)

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .