Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 5 down vote accepted

From this answer on Stack Overflow

type nul >file
share|improve this answer
echo. 2> file

Give that one a try

share|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. :) –  Ƭᴇcʜιᴇ007 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 :) –  8088 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'. –  8088 Apr 20 '11 at 12:52
copy con file [Enter]
[F6] (or [Ctrl-Z]) [Enter]

:)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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