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.
You could also use:
The debug output for
echo.
will almost definitely be empty.copy con SomeFile.txt Enter
Ctrl-Z Enter
This worked for me,
Here's another way I found today, got ideas from other answers but it worked
Eg.
This would show an error message in the command prompt that ,
xyz
is not as an internal or external command, operable program or batch file.But the weird thing I found was the file is being created in the directory even if the command is not a standard windows command.
Reading comments on my post, I have to admit I didn't read the question right.
On the Windows command-line, one way would be to use fsutil:
An example:
Below is for *nix command-line.
This command changes your modified date of a file or creates it if file is not found.
type nul>filename
will create a new empty file.Sorry I'm late.
UPDATE: Also
copy nul filename
works without redirecting (more obvious solution).First create your file so that it exists:
Then overwrite the created file with an empty version using the
copy
command: