How to create an empty file at the DOS/Windows command-line?
I tried:
copy nul > file.txt
but it always displays that a file was copied.
Is there any other method in the standard cmd?
It should be a method that does not require the touch command from Cygwin or any other nonstandard commands. The command needs to run from a script so keystrokes cannot be used.
Yet another method that creates a zero byte file:
Try this:
See: superUser
I read many threads but it is not the shortest way.
Please use command:
>copy /b NUL empty_file.txt
Without redirection, Luc Vu or Erik Konstantopoulos point out to:
"How to create empty text file from a batch file?" (2008) also points to:
Nomad mentions an original one:
In the same spirit, Samuel suggests in the comments:
It does give an error:
But this error is on stderr. And
>
only redirects stdout, where nothing have been produced.Hence the creation of an empty file. The error message can be disregarded here.
(Original answer, November 2009)
(
echo ""
would actually put "" in the file! Andecho
without the '.' would put "Command ECHO activated
" in the file...)Note: the resulting file is not empty but includes a return line sequence: 2 bytes.
This discussion points to a true batch solution for a real empty file:
Since here the "string to the right of the equal sign" is empty... the result is an empty file.
The difference with
cd. > filename
(which is mentioned in Patrick Cuff's answer and does also produce a 0-byte-length file) is that this "bit of redirection" (the<nul...
trick) can be used to echo lines without any CR:this is the cleanest way I know.
echo '' > %1
. (name the file as touch.bat)touch temp.txt
creates temp.txt file)check this article for more information.