How to create an empty file at the command line in

2019-01-12 13:14发布

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.

30条回答
不美不萌又怎样
2楼-- · 2019-01-12 13:39

Here's another way:

cd. > filename
查看更多
时光不老,我们不散
3楼-- · 2019-01-12 13:40

Here is yet another way:

rem/ > file.ext

The slash / is mandatory; without it the redirection part was commented out by rem.

查看更多
趁早两清
4楼-- · 2019-01-12 13:42

Run CMD in admistrator mode and type this:

NUL > file_name.extention

or you type this

echo .> file_name.extention
查看更多
霸刀☆藐视天下
5楼-- · 2019-01-12 13:44

Use copy > your_file_name.extension in command prompt like

P:\excecise> copy > Sample.txt
查看更多
不美不萌又怎样
6楼-- · 2019-01-12 13:44

so you can create an empty file with

'' > newfile.txt

navigate to the directory and type the above command in PowerShell window.

Note this will not work on windows command prompt.

查看更多
Ridiculous、
7楼-- · 2019-01-12 13:44

Today I've discovered a new one :)

This will change the command line window title, but will also create a empty file.

title > file.txt
查看更多
登录 后发表回答