本文介绍了在Windows中的命令行上创建一个空文件(例如linux touch命令)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows计算机上,我收到此错误

On a windows machine I get this error

我正在遵循这些说明,这些说明似乎是特定于Linux的,但在标准Windows上命令行无法像这样工作:

I was following these instructions which seem to be linux specific, but on a standard windows commandline it does not work like this:

touch index.html app.js style.css

是否存在与linux/mac os/unix world中的'touch'命令等效的Windows?我是否需要手动创建这些文件(并修改它们以更改时间戳)才能实现这种命令?我正在使用node,而且看起来不是很... node-ish ...

Is there a windows equivalent of the 'touch' command from the linux / mac os / unix world ? Do I need to create these files by hand (and modify them to change the timestamp) in order to implement this sort of command? I am working with node and that doesn't seem very ... node-ish...

推荐答案

在Windows命令行(如cmd)上替换touch命令的一种简单方法是:

An easy way to replace the touch command on a windows command line like cmd would be:

type nul > your_file.txt

这将在 your_file.txt 文件中创建0个字节.

This will create 0 bytes in the your_file.txt file.

这也是在Windows批处理文件中使用的好方法.

This would also be a good solution to use in windows batch files.

另一种实现方法是使用 echo 命令:

Another way of doing it is by using the echo command:

echo.> your_file.txt

回声.-将创建一个文件,其中只有一个空行.

echo. - will create a file with one empty line in it.

如果您需要保留文件的内容,请使用>> 而不是>

If you need to preserve the content of the file use >> instead of >

>   Creates a new file
>>  Preserves content of the file

示例

type nul >> your_file.txt


您还可以使用致电命令.

示例:

call >> your_file.txt

这篇关于在Windows中的命令行上创建一个空文件(例如linux touch命令)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 18:43