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.

link|improve this question
feedback

3 Answers

up vote 4 down vote accepted

From this answer on Stack Overflow

type nul >file
link|improve this answer
feedback
echo. 2> file

Give that one a try

link|improve this answer
+1 Don't know who marked this down as it does work – Linker3000 Apr 19 '11 at 22:29
+1: Because I learned something, and this is a cool hack. :) – techie007 Apr 19 '11 at 23:25
You can use any command, so if you wanted to make it even shorter how about: cd 2> file :) – Gareth Apr 20 '11 at 6:09
@Gareth, think you meant echo 2> file although using the period after echo (echo.) will turn echo off to stop any other echo related messages showing – Sandeep Bansal Apr 20 '11 at 12:46
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 Apr 20 '11 at 12:52
feedback
copy con file [Enter]
[F6] (or [Ctrl-Z]) [Enter]

:)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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