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.
Try this :
abc > myFile.txt
First, it will create a file with namemyFile.txt
in present working directory (in command prompt). Then it will run the commandabc
which is not a valid command. In this way, you have gotten a new empty file with the namemyFile.txt
.On Windows I tried doing this
and it created a file named fff1.txt with file size of 0kb
I didn't find any commands other than this that could create a empty file.
Yet another way:
Just I have tried in windows
then Press Enter Key then Press Ctrl+Z Enter
And its worked for me.
For Ubuntu usually I am creating a file using VI command
It will open the file then press ESC key then type :wp then press enter key. It will create a new file with empty data.
I believe this works on Windows/DOS, but my last hands-on experience with either is quite a while ago. I do know for a fact that it works on basically any POSIX compliant OS.
You can write your own touch.